Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,29 +2,24 @@ import gradio as gr
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
|
5 |
-
# Load API key from environment variable
|
6 |
api_key = os.getenv("HF_API_KEY")
|
7 |
-
|
8 |
-
# Initialize the InferenceClient
|
9 |
client = InferenceClient(provider="auto", api_key=api_key)
|
10 |
-
|
11 |
-
# List of available models
|
12 |
model_list = ["Qwen/Qwen-Image", "black-forest-labs/FLUX.1-dev"]
|
13 |
|
14 |
-
# Function to generate image from text prompt
|
15 |
def generate_image(prompt, model_name):
|
16 |
image = client.text_to_image(prompt, model=model_name)
|
17 |
return image
|
18 |
|
19 |
-
|
20 |
-
with gr.Blocks() as demo:
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
output_image = gr.Image(type="pil", label="Generated Image")
|
27 |
|
28 |
-
|
|
|
29 |
|
|
|
30 |
demo.launch()
|
|
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
|
|
|
5 |
api_key = os.getenv("HF_API_KEY")
|
|
|
|
|
6 |
client = InferenceClient(provider="auto", api_key=api_key)
|
|
|
|
|
7 |
model_list = ["Qwen/Qwen-Image", "black-forest-labs/FLUX.1-dev"]
|
8 |
|
|
|
9 |
def generate_image(prompt, model_name):
|
10 |
image = client.text_to_image(prompt, model=model_name)
|
11 |
return image
|
12 |
|
13 |
+
def app():
|
14 |
+
with gr.Blocks() as demo:
|
15 |
+
gr.Markdown("## Text to Image Generator")
|
16 |
+
prompt = gr.Textbox(label="Prompt")
|
17 |
+
model = gr.Dropdown(choices=model_list, label="Model", value=model_list[0])
|
18 |
+
btn = gr.Button("Generate")
|
19 |
+
output = gr.Image(type="pil")
|
|
|
20 |
|
21 |
+
btn.click(generate_image, inputs=[prompt, model], outputs=output)
|
22 |
+
return demo
|
23 |
|
24 |
+
demo = app()
|
25 |
demo.launch()
|