Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
6 |
def update_model(selected_model, use_textbox, custom_model):
|
7 |
if use_textbox:
|
8 |
return custom_model # Return the custom model from textbox
|
9 |
else:
|
10 |
return selected_model # Return the selected model from dropdown
|
11 |
|
12 |
-
|
13 |
# Initialize Hugging Face Inference Client
|
14 |
def get_client(model_name):
|
15 |
return InferenceClient(model=model_name)
|
@@ -32,13 +29,14 @@ with gr.Blocks() as demo:
|
|
32 |
}
|
33 |
|
34 |
gr.Markdown("# Text to Image Generator using Hugging Face Inference Client")
|
|
|
35 |
with gr.Row():
|
36 |
use_textbox = gr.Checkbox(label="Use Custom Model", value=False)
|
37 |
|
38 |
with gr.Row():
|
39 |
# Input for text prompt
|
40 |
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...")
|
41 |
-
|
42 |
# Button to generate image
|
43 |
generate_button = gr.Button("Generate Image")
|
44 |
|
@@ -49,20 +47,19 @@ with gr.Blocks() as demo:
|
|
49 |
choices=list(model_options.keys()), # Display model names
|
50 |
value="FLUX 1.0 (black-forest-labs)", # Default model
|
51 |
)
|
52 |
-
|
|
|
53 |
|
54 |
output = gr.Textbox(label="Selected Model", interactive=False)
|
55 |
|
56 |
-
|
57 |
-
|
58 |
with gr.Row():
|
59 |
submit_button = gr.Button("Submit Option")
|
|
|
60 |
with gr.Column():
|
61 |
# Image output
|
62 |
image_output = gr.Image(label="Generated Image")
|
63 |
|
64 |
-
|
65 |
-
# Event to update the selected model based on the checkbox
|
66 |
use_textbox.change(
|
67 |
lambda checked: model_dropdown.update(visible=not checked, value=None),
|
68 |
inputs=[use_textbox],
|
@@ -76,15 +73,18 @@ with gr.Blocks() as demo:
|
|
76 |
)
|
77 |
|
78 |
# Button to confirm selection
|
79 |
-
|
80 |
submit_button.click(
|
81 |
update_model,
|
82 |
inputs=[model_dropdown, use_textbox, custom_model_textbox],
|
83 |
outputs=[output]
|
84 |
-
)
|
85 |
|
86 |
-
# Link the button click to the function
|
87 |
-
generate_button.click(
|
|
|
|
|
|
|
|
|
88 |
|
89 |
# Launch the Gradio app
|
90 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
|
|
|
|
4 |
def update_model(selected_model, use_textbox, custom_model):
|
5 |
if use_textbox:
|
6 |
return custom_model # Return the custom model from textbox
|
7 |
else:
|
8 |
return selected_model # Return the selected model from dropdown
|
9 |
|
|
|
10 |
# Initialize Hugging Face Inference Client
|
11 |
def get_client(model_name):
|
12 |
return InferenceClient(model=model_name)
|
|
|
29 |
}
|
30 |
|
31 |
gr.Markdown("# Text to Image Generator using Hugging Face Inference Client")
|
32 |
+
|
33 |
with gr.Row():
|
34 |
use_textbox = gr.Checkbox(label="Use Custom Model", value=False)
|
35 |
|
36 |
with gr.Row():
|
37 |
# Input for text prompt
|
38 |
prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...")
|
39 |
+
|
40 |
# Button to generate image
|
41 |
generate_button = gr.Button("Generate Image")
|
42 |
|
|
|
47 |
choices=list(model_options.keys()), # Display model names
|
48 |
value="FLUX 1.0 (black-forest-labs)", # Default model
|
49 |
)
|
50 |
+
|
51 |
+
custom_model_textbox = gr.Textbox(label="Enter Custom Model", placeholder="Type your model name here", visible=False)
|
52 |
|
53 |
output = gr.Textbox(label="Selected Model", interactive=False)
|
54 |
|
|
|
|
|
55 |
with gr.Row():
|
56 |
submit_button = gr.Button("Submit Option")
|
57 |
+
|
58 |
with gr.Column():
|
59 |
# Image output
|
60 |
image_output = gr.Image(label="Generated Image")
|
61 |
|
62 |
+
# Event to update the selected model based on the checkbox
|
|
|
63 |
use_textbox.change(
|
64 |
lambda checked: model_dropdown.update(visible=not checked, value=None),
|
65 |
inputs=[use_textbox],
|
|
|
73 |
)
|
74 |
|
75 |
# Button to confirm selection
|
|
|
76 |
submit_button.click(
|
77 |
update_model,
|
78 |
inputs=[model_dropdown, use_textbox, custom_model_textbox],
|
79 |
outputs=[output]
|
80 |
+
)
|
81 |
|
82 |
+
# Link the button click to the image generation function
|
83 |
+
generate_button.click(
|
84 |
+
generate_image,
|
85 |
+
inputs=[prompt_input, output],
|
86 |
+
outputs=image_output
|
87 |
+
)
|
88 |
|
89 |
# Launch the Gradio app
|
90 |
demo.launch()
|