Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,7 +11,7 @@ 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)":
|
|
@@ -21,13 +21,26 @@ def generate_images(text, selected_model):
|
|
| 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(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
results.append(result)
|
| 32 |
|
| 33 |
return results
|
|
@@ -37,28 +50,57 @@ def stop_generation():
|
|
| 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...")
|
| 46 |
-
model_selector = gr.Radio(
|
| 47 |
-
["Model 1 (Turbo Realism)", "Model 2 (Face Projection)"],
|
| 48 |
-
label="Select Model",
|
| 49 |
-
value="Model 1 (Turbo Realism)"
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
with gr.Row():
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
with gr.Row():
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
output3 = gr.Image(label="Generated Image 3")
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
interface.launch()
|
|
|
|
| 11 |
|
| 12 |
stop_event = threading.Event()
|
| 13 |
|
| 14 |
+
def generate_images(text, selected_model, steps, cfg_scale, seed, width, height):
|
| 15 |
stop_event.clear()
|
| 16 |
|
| 17 |
if selected_model == "Model 1 (Turbo Realism)":
|
|
|
|
| 21 |
else:
|
| 22 |
return ["Invalid model selection."] * 3
|
| 23 |
|
| 24 |
+
# Convert seed to integer (handle empty/None)
|
| 25 |
+
try:
|
| 26 |
+
seed = int(seed) if seed not in [None, ""] else -1
|
| 27 |
+
except:
|
| 28 |
+
seed = -1
|
| 29 |
+
|
| 30 |
results = []
|
| 31 |
for i in range(3):
|
| 32 |
if stop_event.is_set():
|
| 33 |
return ["Image generation stopped by user."] * 3
|
| 34 |
|
| 35 |
modified_text = f"{text} variation {i+1}"
|
| 36 |
+
result = model(
|
| 37 |
+
modified_text,
|
| 38 |
+
num_inference_steps=int(steps),
|
| 39 |
+
guidance_scale=float(cfg_scale),
|
| 40 |
+
height=int(height),
|
| 41 |
+
width=int(width),
|
| 42 |
+
seed=seed if seed != -1 else None
|
| 43 |
+
)
|
| 44 |
results.append(result)
|
| 45 |
|
| 46 |
return results
|
|
|
|
| 50 |
stop_event.set()
|
| 51 |
return ["Generation stopped."] * 3
|
| 52 |
|
| 53 |
+
with gr.Blocks() as interface:
|
| 54 |
gr.Markdown(
|
| 55 |
"### ⚠ Sorry for the inconvenience. The Space is currently running on the CPU, which might affect performance. We appreciate your understanding."
|
| 56 |
)
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
with gr.Row():
|
| 59 |
+
text_input = gr.Textbox(label="Prompt", placeholder="Type your imagination here...")
|
| 60 |
+
model_selector = gr.Radio(
|
| 61 |
+
["Model 1 (Turbo Realism)", "Model 2 (Face Projection)"],
|
| 62 |
+
label="Model Selection",
|
| 63 |
+
value="Model 1 (Turbo Realism)"
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
with gr.Accordion("Advanced Parameters", open=False):
|
| 67 |
+
with gr.Row():
|
| 68 |
+
steps = gr.Slider(1, 150, value=25, label="Inference Steps", info="(20-50 for quality/speed balance)")
|
| 69 |
+
cfg_scale = gr.Slider(1.0, 20.0, value=7.5, label="CFG Scale", info="(7-12 for good balance)")
|
| 70 |
+
seed = gr.Number(label="Seed", value=-1, precision=0, info="-1 for random")
|
| 71 |
+
|
| 72 |
+
with gr.Row():
|
| 73 |
+
width = gr.Dropdown(
|
| 74 |
+
choices=["512", "640", "768", "896", "1024"],
|
| 75 |
+
value="512",
|
| 76 |
+
label="Width",
|
| 77 |
+
allow_custom_value=True
|
| 78 |
+
)
|
| 79 |
+
height = gr.Dropdown(
|
| 80 |
+
choices=["512", "640", "768", "896", "1024"],
|
| 81 |
+
value="512",
|
| 82 |
+
label="Height",
|
| 83 |
+
allow_custom_value=True
|
| 84 |
+
)
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
+
generate_button = gr.Button("Generate 3 Images 🎨", variant="primary")
|
| 88 |
+
stop_button = gr.Button("Stop Generation", variant="stop")
|
|
|
|
| 89 |
|
| 90 |
+
with gr.Row():
|
| 91 |
+
output1 = gr.Image(label="Variant 1", type="pil", show_label=True)
|
| 92 |
+
output2 = gr.Image(label="Variant 2", type="pil", show_label=True)
|
| 93 |
+
output3 = gr.Image(label="Variant 3", type="pil", show_label=True)
|
| 94 |
+
|
| 95 |
+
generate_button.click(
|
| 96 |
+
generate_images,
|
| 97 |
+
inputs=[text_input, model_selector, steps, cfg_scale, seed, width, height],
|
| 98 |
+
outputs=[output1, output2, output3]
|
| 99 |
+
)
|
| 100 |
+
stop_button.click(
|
| 101 |
+
stop_generation,
|
| 102 |
+
inputs=[],
|
| 103 |
+
outputs=[output1, output2, output3]
|
| 104 |
+
)
|
| 105 |
|
| 106 |
interface.launch()
|