Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import threading
|
|
3 |
import os
|
4 |
import torch
|
5 |
|
6 |
-
|
7 |
os.environ["OMP_NUM_THREADS"] = str(os.cpu_count())
|
8 |
torch.set_num_threads(os.cpu_count())
|
9 |
|
@@ -33,13 +32,14 @@ def generate_images(text, selected_model):
|
|
33 |
|
34 |
return results
|
35 |
|
36 |
-
|
37 |
def stop_generation():
|
|
|
38 |
stop_event.set()
|
|
|
39 |
|
40 |
with gr.Blocks() as interface:
|
41 |
gr.Markdown(
|
42 |
-
"### ⚠ Sorry for the inconvenience. The
|
43 |
)
|
44 |
|
45 |
text_input = gr.Textbox(label="Type here your imagination:", placeholder="Type your prompt...")
|
@@ -50,7 +50,7 @@ with gr.Blocks() as interface:
|
|
50 |
)
|
51 |
|
52 |
with gr.Row():
|
53 |
-
generate_button = gr.Button("Generate 3 Images")
|
54 |
stop_button = gr.Button("Stop Image Generation")
|
55 |
|
56 |
with gr.Row():
|
@@ -59,6 +59,6 @@ with gr.Blocks() as interface:
|
|
59 |
output3 = gr.Image(label="Generated Image 3")
|
60 |
|
61 |
generate_button.click(generate_images, inputs=[text_input, model_selector], outputs=[output1, output2, output3])
|
62 |
-
stop_button.click(stop_generation, inputs=[], outputs=[])
|
63 |
|
64 |
interface.launch()
|
|
|
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 |
|
|
|
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 |
gr.Markdown(
|
42 |
+
"### ⚠ Sorry for the inconvenience. The Space is currently running on the CPU, which might affect performance. We appreciate your understanding."
|
43 |
)
|
44 |
|
45 |
text_input = gr.Textbox(label="Type here your imagination:", placeholder="Type your prompt...")
|
|
|
50 |
)
|
51 |
|
52 |
with gr.Row():
|
53 |
+
generate_button = gr.Button("Generate 3 Images 🎨")
|
54 |
stop_button = gr.Button("Stop Image Generation")
|
55 |
|
56 |
with gr.Row():
|
|
|
59 |
output3 = gr.Image(label="Generated Image 3")
|
60 |
|
61 |
generate_button.click(generate_images, inputs=[text_input, model_selector], outputs=[output1, output2, output3])
|
62 |
+
stop_button.click(stop_generation, inputs=[], outputs=[output1, output2, output3])
|
63 |
|
64 |
interface.launch()
|