Saravutw commited on
Commit
89433a3
ยท
verified ยท
1 Parent(s): 5863f9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +58 -21
app.py CHANGED
@@ -1,24 +1,61 @@
1
- import os
2
- import spaces
3
- import gradio as gr
4
- import numpy as np
5
- from PIL import Image
6
- import random
7
- from diffusers import DiffusionPipeline, AutoPipelineForText2Image
8
- from transformers import pipeline as transformers_pipeline
9
- import re
10
- from cohere import ClientV2
11
- import sys
12
  import torch
 
 
 
13
 
14
- import ast #์ถ”๊ฐ€ ์‚ฝ์ž…, requirements: albumentations ์ถ”๊ฐ€
15
- script_repr = os.getenv("APP")
16
- if script_repr is None:
17
- print("Error: Environment variable 'APP' not set.")
18
- sys.exit(1)
19
 
20
- try:
21
- exec(script_repr)
22
- except Exception as e:
23
- print(f"Error executing script: {e}")
24
- sys.exit(1)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import torch
2
+ from diffusers import AutoPipelineForText2Image
3
+ from peft import PeftModel, PeftConfig
4
+ import gradio as gr # Import Gradio
5
 
6
+ # ๊ธฐ๊ธฐ ์„ค์ •
7
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 
 
 
8
 
9
+ # ๊ธฐ๋ณธ ๋ชจ๋ธ ๋กœ๋“œ
10
+ print("๊ธฐ๋ณธ FLUX ๋ชจ๋ธ ๋กœ๋“œ ์ค‘...")
11
+ pipe = AutoPipelineForText2Image.from_pretrained(
12
+ "black-forest-labs/FLUX.1-dev",
13
+ torch_dtype=torch.float16 # bfloat16 ๋Œ€์‹  float16 ์‚ฌ์šฉ
14
+ )
15
+ pipe.to(device)
16
+
17
+ # Uncensored LoRA ๋กœ๋“œ
18
+ print("Uncensored LoRA ๋กœ๋“œ ์ค‘...")
19
+ pipe.load_lora_weights(
20
+ 'Heartsync/Flux-NSFW-uncensored',
21
+ weight_name='lora.safetensors',
22
+ adapter_name="uncensored"
23
+ )
24
+
25
+ # ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํ•จ์ˆ˜ ์ •์˜
26
+ def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps, width, height, seed):
27
+ generator = torch.Generator(device=device).manual_seed(seed)
28
+
29
+ image = pipe(
30
+ prompt=prompt,
31
+ negative_prompt=negative_prompt,
32
+ guidance_scale=guidance_scale,
33
+ num_inference_steps=num_inference_steps,
34
+ width=width,
35
+ height=height,
36
+ generator=generator,
37
+ ).images[0]
38
+
39
+ # ์ด๋ฏธ์ง€ ์ €์žฅ (์„ ํƒ ์‚ฌํ•ญ, ํ•„์š”์— ๋”ฐ๋ผ ํ™œ์„ฑํ™”/๋น„ํ™œ์„ฑํ™”)
40
+ # image.save("generated_image.png")
41
+ return image
42
+
43
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ƒ์„ฑ
44
+ iface = gr.Interface(
45
+ fn=generate_image,
46
+ inputs=[
47
+ gr.Textbox(label="Prompt", value="A woman in a sheer white dress standing on a beach at sunset, backlit so her silhouette is visible through the thin fabric, shot with Canon EOS R5, 85mm f/1.2 lens, golden hour natural lighting, professional composition, hyperrealistic detail, masterpiece quality, 8K resolution."),
48
+ gr.Textbox(label="Negative Prompt", value="text, watermark, signature, cartoon, anime, illustration, painting, drawing, low quality, blurry"),
49
+ gr.Slider(minimum=1.0, maximum=20.0, step=0.1, value=7.0, label="Guidance Scale"),
50
+ gr.Slider(minimum=10, maximum=100, step=1, value=28, label="Number of Inference Steps"),
51
+ gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Width"),
52
+ gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Height"),
53
+ gr.Slider(minimum=0, maximum=99999, step=1, value=42, label="Seed")
54
+ ],
55
+ outputs="image",
56
+ title="FLUX.1-dev with Uncensored LoRA",
57
+ description="Generate images using FLUX.1-dev with a loaded Uncensored LoRA model."
58
+ )
59
+
60
+ # ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰ (share=True)
61
+ iface.launch(share=True)