Upload 2 files
Browse files- app.py +110 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler
|
2 |
+
import torch
|
3 |
+
import gradio as gr
|
4 |
+
import spaces
|
5 |
+
|
6 |
+
|
7 |
+
lora_path = "OedoSoldier/detail-tweaker-lora"
|
8 |
+
|
9 |
+
@spaces.GPU
|
10 |
+
def generate_image(prompt, negative_prompt, num_inference_steps=50, guidance_scale=7.5,model="Real6.0"):
|
11 |
+
"""
|
12 |
+
Generate an image using Stable Diffusion based on the input prompt
|
13 |
+
"""
|
14 |
+
|
15 |
+
if model == "Real5.0":
|
16 |
+
model_id = "SG161222/Realistic_Vision_V5.0_noVAE"
|
17 |
+
|
18 |
+
elif model == "Real5.1":
|
19 |
+
model_id = "SG161222/Realistic_Vision_V5.1_noVAE"
|
20 |
+
|
21 |
+
else:
|
22 |
+
model_id = "SG161222/Realistic_Vision_V6.0_B1_noVAE"
|
23 |
+
|
24 |
+
|
25 |
+
pipe = DiffusionPipeline.from_pretrained(model_id).to("cuda")
|
26 |
+
|
27 |
+
if model == "Real6.0":
|
28 |
+
pipe.safety_checker = lambda images, **kwargs: (images, [False] * len(images))
|
29 |
+
|
30 |
+
pipe.load_lora_weights(lora_path)
|
31 |
+
|
32 |
+
pipe.scheduler = DPMSolverMultistepScheduler.from_config(
|
33 |
+
pipe.scheduler.config,
|
34 |
+
algorithm_type="dpmsolver++",
|
35 |
+
use_karras_sigmas=True
|
36 |
+
)
|
37 |
+
|
38 |
+
|
39 |
+
# Generate the image
|
40 |
+
image = pipe(
|
41 |
+
prompt = prompt,
|
42 |
+
negative_prompt = negative_prompt,
|
43 |
+
cross_attention_kwargs = {"scale":1},
|
44 |
+
num_inference_steps = num_inference_steps,
|
45 |
+
guidance_scale = guidance_scale,
|
46 |
+
width = 960,
|
47 |
+
height = 960
|
48 |
+
).images[0]
|
49 |
+
|
50 |
+
return image
|
51 |
+
|
52 |
+
# Create the Gradio interface
|
53 |
+
with gr.Blocks() as demo:
|
54 |
+
gr.Markdown("# ProFaker ImageGen")
|
55 |
+
|
56 |
+
with gr.Row():
|
57 |
+
with gr.Column():
|
58 |
+
# Input components
|
59 |
+
prompt = gr.Textbox(
|
60 |
+
label="Prompt",
|
61 |
+
placeholder="Enter your image description here...",
|
62 |
+
value="a photo of an astronaut riding a horse on mars"
|
63 |
+
)
|
64 |
+
negative_prompt = gr.Textbox(
|
65 |
+
label="Negative Prompt",
|
66 |
+
placeholder="Enter what you don't want in photo",
|
67 |
+
)
|
68 |
+
steps_slider = gr.Slider(
|
69 |
+
minimum=1,
|
70 |
+
maximum=100,
|
71 |
+
value=50,
|
72 |
+
step=1,
|
73 |
+
label="Number of Inference Steps"
|
74 |
+
)
|
75 |
+
guidance_slider = gr.Slider(
|
76 |
+
minimum=1,
|
77 |
+
maximum=20,
|
78 |
+
value=7.5,
|
79 |
+
step=0.5,
|
80 |
+
label="Guidance Scale"
|
81 |
+
)
|
82 |
+
model = gr.Dropdown(
|
83 |
+
choices=["Real6.0","Real5.1","Real5.0"],
|
84 |
+
value="Real6.0",
|
85 |
+
label="Model",
|
86 |
+
)
|
87 |
+
generate_button = gr.Button("Generate Image")
|
88 |
+
|
89 |
+
with gr.Column():
|
90 |
+
# Output component
|
91 |
+
image_output = gr.Image(label="Generated Image")
|
92 |
+
|
93 |
+
# Connect the interface to the generation function
|
94 |
+
generate_button.click(
|
95 |
+
fn=generate_image,
|
96 |
+
inputs=[prompt, negative_prompt, steps_slider, guidance_slider, model],
|
97 |
+
outputs=image_output
|
98 |
+
)
|
99 |
+
|
100 |
+
gr.Markdown("""
|
101 |
+
## Instructions
|
102 |
+
1. Enter your desired image description in the prompt field
|
103 |
+
2. Adjust the inference steps (higher = better quality but slower)
|
104 |
+
3. Adjust the guidance scale (higher = more prompt adherence)
|
105 |
+
4. Click 'Generate Image' and wait for the result
|
106 |
+
""")
|
107 |
+
|
108 |
+
# Launch the interface
|
109 |
+
if __name__ == "__main__":
|
110 |
+
demo.launch(share=True)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
spaces
|
2 |
+
gradio
|
3 |
+
diffusers
|
4 |
+
transformers
|
5 |
+
accelerate
|
6 |
+
peft
|