gokaygokay commited on
Commit
58cbf34
1 Parent(s): eead421

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -25
app.py CHANGED
@@ -49,38 +49,73 @@ def generate_image(api_key, model, prompt, image_size, num_inference_steps, guid
49
 
50
  def update_visible_components(model):
51
  if model == "Flux Pro":
52
- return [gr.update(visible=True), gr.update(visible=True), gr.update(visible=False)]
 
 
 
 
 
53
  elif model == "Flux Dev":
54
- return [gr.update(visible=True), gr.update(visible=False), gr.update(visible=True)]
 
 
 
 
 
55
  else: # Flux Schnell
56
- return [gr.update(visible=False), gr.update(visible=False), gr.update(visible=True)]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
 
58
- with gr.Blocks() as demo:
59
- gr.Markdown("# Flux Image Generation")
60
-
61
- api_key = gr.Textbox(type="password", label="FAL API Key")
62
-
63
  with gr.Row():
64
- model = gr.Dropdown(choices=["Flux Pro", "Flux Dev", "Flux Schnell"], label="Model", value="Flux Pro")
65
- image_size = gr.Dropdown(choices=["square_hd", "square", "portrait_4_3", "portrait_16_9", "landscape_4_3", "landscape_16_9"], label="Image Size", value="landscape_4_3")
66
-
67
- prompt = gr.Textbox(label="Prompt", lines=3)
68
- num_inference_steps = gr.Slider(1, 100, value=28, step=1, label="Number of Inference Steps")
69
- guidance_scale = gr.Slider(0, 20, value=3.5, step=0.1, label="Guidance Scale")
70
- num_images = gr.Slider(1, 10, value=1, step=1, label="Number of Images")
71
- safety_tolerance = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6"], label="Safety Tolerance", value="2")
72
- enable_safety_checker = gr.Checkbox(label="Enable Safety Checker", value=True)
73
- seed = gr.Number(label="Seed", value=-1)
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
- generate_button = gr.Button("Generate Images")
76
- output_images = gr.Gallery(label="Generated Images")
77
 
78
- model.change(update_visible_components, inputs=[model], outputs=[guidance_scale, safety_tolerance, enable_safety_checker])
79
 
80
- generate_button.click(
81
- generate_image,
82
- inputs=[api_key, model, prompt, image_size, num_inference_steps, guidance_scale, num_images, safety_tolerance, enable_safety_checker, seed],
83
- outputs=output_images
 
 
 
84
  )
85
 
86
  demo.launch()
 
49
 
50
  def update_visible_components(model):
51
  if model == "Flux Pro":
52
+ return [
53
+ gr.update(visible=True, value=28),
54
+ gr.update(visible=True, value=3.5),
55
+ gr.update(visible=True, value="2"),
56
+ gr.update(visible=False)
57
+ ]
58
  elif model == "Flux Dev":
59
+ return [
60
+ gr.update(visible=True, value=28),
61
+ gr.update(visible=True, value=3.5),
62
+ gr.update(visible=False),
63
+ gr.update(visible=True, value=True)
64
+ ]
65
  else: # Flux Schnell
66
+ return [
67
+ gr.update(visible=True, value=4),
68
+ gr.update(visible=False),
69
+ gr.update(visible=False),
70
+ gr.update(visible=True, value=True)
71
+ ]
72
+
73
+ with gr.Blocks(theme='bethecloud/storj_theme') as demo:
74
+ gr.HTML("""
75
+ <h1 align="center">Flux AI Image Generation</h1>
76
+ <p align="center">
77
+ <a href="https://www.fal.ai/" target="_blank">[FAL AI Website]</a>
78
+ <a href="https://github.com/fal-ai/fal" target="_blank">[FAL AI GitHub]</a>
79
+ </p>
80
+ """)
81
 
 
 
 
 
 
82
  with gr.Row():
83
+ with gr.Column(scale=1):
84
+ api_key = gr.Textbox(type="password", label="FAL API Key")
85
+ model = gr.Dropdown(
86
+ label="Model",
87
+ choices=["Flux Pro", "Flux Dev", "Flux Schnell"],
88
+ value="Flux Pro"
89
+ )
90
+ prompt = gr.Textbox(label="Prompt", lines=3, placeholder="Add your prompt here")
91
+ image_size = gr.Dropdown(
92
+ choices=["square_hd", "square", "portrait_4_3", "portrait_16_9", "landscape_4_3", "landscape_16_9"],
93
+ label="Image Size",
94
+ value="landscape_4_3"
95
+ )
96
+
97
+ with gr.Accordion("Advanced settings", open=False):
98
+ num_inference_steps = gr.Slider(1, 100, 28, step=1, label="Number of Inference Steps")
99
+ guidance_scale = gr.Slider(0, 20, 3.5, step=0.1, label="Guidance Scale")
100
+ num_images = gr.Slider(1, 10, 1, step=1, label="Number of Images")
101
+ safety_tolerance = gr.Dropdown(choices=["1", "2", "3", "4", "5", "6"], label="Safety Tolerance", value="2")
102
+ enable_safety_checker = gr.Checkbox(label="Enable Safety Checker", value=True)
103
+ seed = gr.Number(label="Seed", value=-1)
104
+
105
+ generate_btn = gr.Button("Generate Image")
106
 
107
+ with gr.Column(scale=1):
108
+ output_gallery = gr.Gallery(label="Generated Images", elem_id="gallery", show_label=False)
109
 
110
+ model.change(update_visible_components, inputs=[model], outputs=[num_inference_steps, guidance_scale, safety_tolerance, enable_safety_checker])
111
 
112
+ generate_btn.click(
113
+ fn=generate_image,
114
+ inputs=[
115
+ api_key, model, prompt, image_size, num_inference_steps,
116
+ guidance_scale, num_images, safety_tolerance, enable_safety_checker, seed
117
+ ],
118
+ outputs=[output_gallery]
119
  )
120
 
121
  demo.launch()