Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,60 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
-
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import threading
|
3 |
+
import os
|
4 |
+
import torch
|
5 |
|
6 |
+
os.environ["OMP_NUM_THREADS"] = str(os.cpu_count())
|
7 |
+
torch.set_num_threads(os.cpu_count())
|
8 |
|
9 |
+
model1 = gr.load("models/prithivMLmods/SD3.5-Turbo-Realism-2.0-LoRA")
|
10 |
+
model2 = gr.load("models/Purz/face-projection")
|
11 |
+
|
12 |
+
stop_event = threading.Event()
|
13 |
+
|
14 |
+
def generate_images(text, selected_model):
|
15 |
+
stop_event.clear()
|
16 |
+
|
17 |
+
if selected_model == "Model 1 (Turbo Realism)":
|
18 |
+
model = model1
|
19 |
+
elif selected_model == "Model 2 (Face Projection)":
|
20 |
+
model = model2
|
21 |
+
else:
|
22 |
+
return ["Invalid model selection."] * 3
|
23 |
+
|
24 |
+
results = []
|
25 |
+
for i in range(3):
|
26 |
+
if stop_event.is_set():
|
27 |
+
return ["Image generation stopped by user."] * 3
|
28 |
+
|
29 |
+
modified_text = f"{text} variation {i+1}"
|
30 |
+
result = model(modified_text)
|
31 |
+
results.append(result)
|
32 |
+
|
33 |
+
return results
|
34 |
+
|
35 |
+
def stop_generation():
|
36 |
+
"""Stops the ongoing image generation by setting the stop_event flag."""
|
37 |
+
stop_event.set()
|
38 |
+
return ["Generation stopped."] * 3
|
39 |
+
|
40 |
+
with gr.Blocks() as interface:#...
|
41 |
+
text_input = gr.Textbox(label="Type here your imagination:", placeholder="Type your prompt...")
|
42 |
+
model_selector = gr.Radio(
|
43 |
+
["Model 1 (Turbo Realism)", "Model 2 (Face Projection)"],
|
44 |
+
label="Select Model",
|
45 |
+
value="Model 1 (Turbo Realism)"
|
46 |
+
)
|
47 |
+
|
48 |
+
with gr.Row():
|
49 |
+
generate_button = gr.Button("Generate 3 Images 🎨")
|
50 |
+
stop_button = gr.Button("Stop Image Generation")
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
output1 = gr.Image(label="Generated Image 1")
|
54 |
+
output2 = gr.Image(label="Generated Image 2")
|
55 |
+
output3 = gr.Image(label="Generated Image 3")
|
56 |
+
|
57 |
+
generate_button.click(generate_images, inputs=[text_input, model_selector], outputs=[output1, output2, output3])
|
58 |
+
stop_button.click(stop_generation, inputs=[], outputs=[output1, output2, output3])
|
59 |
+
|
60 |
+
interface.launch()
|