Spaces:
Sleeping
Sleeping
Updated debug to True
Browse files
app.py
CHANGED
|
@@ -1,67 +1,67 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from gradio_client import Client
|
| 3 |
-
|
| 4 |
-
# Connect to the Qwen-Image-Fast model
|
| 5 |
-
client = Client("multimodalart/Qwen-Image-Fast")
|
| 6 |
-
|
| 7 |
-
# Function to generate images
|
| 8 |
-
def generate_image(
|
| 9 |
-
prompt,
|
| 10 |
-
seed=0,
|
| 11 |
-
randomize_seed=True,
|
| 12 |
-
aspect_ratio="16:9",
|
| 13 |
-
guidance_scale=1,
|
| 14 |
-
num_inference_steps=8,
|
| 15 |
-
prompt_enhance=True,
|
| 16 |
-
):
|
| 17 |
-
if not prompt.strip():
|
| 18 |
-
return None, "⚠️ Please enter a prompt."
|
| 19 |
-
|
| 20 |
-
try:
|
| 21 |
-
result = client.predict(
|
| 22 |
-
prompt=prompt,
|
| 23 |
-
seed=seed,
|
| 24 |
-
randomize_seed=randomize_seed,
|
| 25 |
-
aspect_ratio=aspect_ratio,
|
| 26 |
-
guidance_scale=guidance_scale,
|
| 27 |
-
num_inference_steps=num_inference_steps,
|
| 28 |
-
prompt_enhance=prompt_enhance,
|
| 29 |
-
api_name="/infer",
|
| 30 |
-
)
|
| 31 |
-
img_info, seed_out = result
|
| 32 |
-
return img_info["url"], f"✅ Image generated! (Seed: {seed_out})"
|
| 33 |
-
except Exception as e:
|
| 34 |
-
return None, f"❌ Error: {str(e)}"
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
# Build Gradio app
|
| 38 |
-
with gr.Blocks(title="Qwen Image Generator") as demo:
|
| 39 |
-
gr.Markdown("## 🎨 Qwen Image Generator\nEnter a **prompt** and customize settings if needed.")
|
| 40 |
-
|
| 41 |
-
with gr.Row():
|
| 42 |
-
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt...", lines=2)
|
| 43 |
-
|
| 44 |
-
with gr.Accordion("⚙️ Customization (Optional)", open=False):
|
| 45 |
-
seed = gr.Number(label="Seed (default: 0)", value=0)
|
| 46 |
-
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 47 |
-
aspect_ratio = gr.Radio(
|
| 48 |
-
["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
|
| 49 |
-
label="Aspect Ratio",
|
| 50 |
-
value="16:9"
|
| 51 |
-
)
|
| 52 |
-
guidance_scale = gr.Slider(1, 10, value=1, step=1, label="Guidance Scale (CFG)")
|
| 53 |
-
num_inference_steps = gr.Slider(1, 50, value=8, step=1, label="Number of Inference Steps")
|
| 54 |
-
prompt_enhance = gr.Checkbox(label="Prompt Enhance", value=True)
|
| 55 |
-
|
| 56 |
-
generate_btn = gr.Button("🚀 Generate Image")
|
| 57 |
-
output_img = gr.Image(label="Generated Image")
|
| 58 |
-
status = gr.Textbox(label="Status", interactive=False)
|
| 59 |
-
|
| 60 |
-
generate_btn.click(
|
| 61 |
-
fn=generate_image,
|
| 62 |
-
inputs=[prompt_input, seed, randomize_seed, aspect_ratio, guidance_scale, num_inference_steps, prompt_enhance],
|
| 63 |
-
outputs=[output_img, status]
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
if __name__ == "__main__":
|
| 67 |
-
demo.launch(server_name="0.0.0.0",server_port=7860,pwa=True)
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client
|
| 3 |
+
|
| 4 |
+
# Connect to the Qwen-Image-Fast model
|
| 5 |
+
client = Client("multimodalart/Qwen-Image-Fast")
|
| 6 |
+
|
| 7 |
+
# Function to generate images
|
| 8 |
+
def generate_image(
|
| 9 |
+
prompt,
|
| 10 |
+
seed=0,
|
| 11 |
+
randomize_seed=True,
|
| 12 |
+
aspect_ratio="16:9",
|
| 13 |
+
guidance_scale=1,
|
| 14 |
+
num_inference_steps=8,
|
| 15 |
+
prompt_enhance=True,
|
| 16 |
+
):
|
| 17 |
+
if not prompt.strip():
|
| 18 |
+
return None, "⚠️ Please enter a prompt."
|
| 19 |
+
|
| 20 |
+
try:
|
| 21 |
+
result = client.predict(
|
| 22 |
+
prompt=prompt,
|
| 23 |
+
seed=seed,
|
| 24 |
+
randomize_seed=randomize_seed,
|
| 25 |
+
aspect_ratio=aspect_ratio,
|
| 26 |
+
guidance_scale=guidance_scale,
|
| 27 |
+
num_inference_steps=num_inference_steps,
|
| 28 |
+
prompt_enhance=prompt_enhance,
|
| 29 |
+
api_name="/infer",
|
| 30 |
+
)
|
| 31 |
+
img_info, seed_out = result
|
| 32 |
+
return img_info["url"], f"✅ Image generated! (Seed: {seed_out})"
|
| 33 |
+
except Exception as e:
|
| 34 |
+
return None, f"❌ Error: {str(e)}"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# Build Gradio app
|
| 38 |
+
with gr.Blocks(title="Qwen Image Generator") as demo:
|
| 39 |
+
gr.Markdown("## 🎨 Qwen Image Generator\nEnter a **prompt** and customize settings if needed.")
|
| 40 |
+
|
| 41 |
+
with gr.Row():
|
| 42 |
+
prompt_input = gr.Textbox(label="Prompt", placeholder="Enter your prompt...", lines=2)
|
| 43 |
+
|
| 44 |
+
with gr.Accordion("⚙️ Customization (Optional)", open=False):
|
| 45 |
+
seed = gr.Number(label="Seed (default: 0)", value=0)
|
| 46 |
+
randomize_seed = gr.Checkbox(label="Randomize Seed", value=True)
|
| 47 |
+
aspect_ratio = gr.Radio(
|
| 48 |
+
["1:1", "16:9", "9:16", "4:3", "3:4", "3:2", "2:3"],
|
| 49 |
+
label="Aspect Ratio",
|
| 50 |
+
value="16:9"
|
| 51 |
+
)
|
| 52 |
+
guidance_scale = gr.Slider(1, 10, value=1, step=1, label="Guidance Scale (CFG)")
|
| 53 |
+
num_inference_steps = gr.Slider(1, 50, value=8, step=1, label="Number of Inference Steps")
|
| 54 |
+
prompt_enhance = gr.Checkbox(label="Prompt Enhance", value=True)
|
| 55 |
+
|
| 56 |
+
generate_btn = gr.Button("🚀 Generate Image")
|
| 57 |
+
output_img = gr.Image(label="Generated Image")
|
| 58 |
+
status = gr.Textbox(label="Status", interactive=False)
|
| 59 |
+
|
| 60 |
+
generate_btn.click(
|
| 61 |
+
fn=generate_image,
|
| 62 |
+
inputs=[prompt_input, seed, randomize_seed, aspect_ratio, guidance_scale, num_inference_steps, prompt_enhance],
|
| 63 |
+
outputs=[output_img, status]
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
if __name__ == "__main__":
|
| 67 |
+
demo.launch(server_name="0.0.0.0",server_port=7860,pwa=True,debub=True)
|