nevreal commited on
Commit
bcb28b5
·
verified ·
1 Parent(s): f4510da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -56
app.py CHANGED
@@ -1,11 +1,7 @@
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):
@@ -19,66 +15,26 @@ def generate_image(prompt, model_name):
19
 
20
  # Gradio interface
21
  with gr.Blocks() as demo:
22
- # List of available models (custom models included)
23
- model_options = {
24
- "Stable Diffusion 2": "stabilityai/stable-diffusion-2",
25
- "Stable Diffusion 1.5": "runwayml/stable-diffusion-v1-5",
26
- "DALL-E Mini": "dalle-mini/dalle-mini",
27
- "FLUX 1.0 (black-forest-labs)": "black-forest-labs/FLUX.1-dev",
28
- "Pony Diffusion V6": "John6666/pony-diffusion-v6-xl-sdxl-spo"
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
-
43
  with gr.Column():
44
  # Dropdown for model selection
45
- model_dropdown = gr.Dropdown(
46
- label="Select Model",
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="enter Model")
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: (not checked, None, "" if checked else None),
65
- inputs=[use_textbox],
66
- outputs=[model_dropdown, custom_model_textbox]
67
- )
68
-
69
- # Button to confirm selection
70
- submit_button.click(
71
- update_model,
72
- inputs=[model_dropdown, use_textbox, custom_model_textbox],
73
- outputs=[output]
74
- )
75
 
76
- # Link the button click to the image generation function
77
- generate_button.click(
78
- generate_image,
79
- inputs=[prompt_input, output],
80
- outputs=image_output
81
- )
82
 
83
  # Launch the Gradio app
84
- demo.launch(share=True)
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+
 
 
 
 
5
 
6
  # Initialize Hugging Face Inference Client
7
  def get_client(model_name):
 
15
 
16
  # Gradio interface
17
  with gr.Blocks() as demo:
 
 
 
 
 
 
 
 
 
18
  gr.Markdown("# Text to Image Generator using Hugging Face Inference Client")
19
 
20
  with gr.Row():
 
 
 
 
 
 
 
 
 
21
  with gr.Column():
22
  # Dropdown for model selection
23
+ prompt_model = gr.Textbox(label="Enter your prompt", placeholder="your model...")
24
+
25
+
26
+ # Input for text prompt
27
+ prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want...")
28
+
29
+ # Button to generate image
30
+ generate_button = gr.Button("Generate Image")
 
 
 
 
31
 
32
  with gr.Column():
33
  # Image output
34
  image_output = gr.Image(label="Generated Image")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
+ # Link the button click to the function
37
+ generate_button.click(generate_image, inputs=[prompt_model, prompt_input], outputs=image_output)
 
 
 
 
38
 
39
  # Launch the Gradio app
40
+ demo.launch()