celinah HF Staff commited on
Commit
83c154c
·
1 Parent(s): 78ad77d
Files changed (1) hide show
  1. app.py +83 -80
app.py CHANGED
@@ -90,92 +90,95 @@ with gr.Blocks(css=css) as demo:
90
  with gr.Sidebar():
91
  gr.Markdown("# Inference Provider")
92
  gr.Markdown(
93
- "This Space showcases the black-forest-labs/FLUX.1-dev model, served by the nebius API. Sign in with your Hugging Face account to use this API."
94
  )
95
- button = gr.LoginButton("Sign in")
96
- button.click(fn=get_token, inputs=[], outputs=[])
97
 
98
- with gr.Row():
99
-
100
- with gr.Tab("Generate Image"):
101
- gr.Markdown(
102
- """# FLUX.1 [schnell] with fal‑ai through HF Inference Providers ⚡\nLearn more about HF Inference Providers [here](https://huggingface.co/docs/inference-providers/index)"""
103
- )
104
 
105
- with gr.Row():
106
- prompt = gr.Text(
107
- label="Prompt",
108
- show_label=False,
109
- max_lines=1,
110
- placeholder="Enter your prompt",
111
- container=False,
112
- )
113
- run_button = gr.Button("Run", scale=0)
114
-
115
- result = gr.Image(label="Result", show_label=False, format="png")
116
-
117
- with gr.Accordion("Advanced Settings", open=False):
118
- seed = gr.Slider(
119
- label="Seed",
120
- minimum=0,
121
- maximum=MAX_SEED,
122
- step=1,
123
- value=42,
124
- )
125
- with gr.Row():
126
- width = gr.Slider(
127
- label="Width",
128
- minimum=256,
129
- maximum=MAX_IMAGE_SIZE,
130
- step=32,
131
- value=1024,
132
- )
133
- height = gr.Slider(
134
- label="Height",
135
- minimum=256,
136
- maximum=MAX_IMAGE_SIZE,
137
- step=32,
138
- value=1024,
139
- )
140
- num_inference_steps = gr.Slider(
141
- label="Number of inference steps",
142
- minimum=1,
143
- maximum=50,
144
- step=1,
145
- value=25,
146
- )
147
-
148
- gr.Examples(
149
- examples=examples,
150
- fn=generate,
151
- inputs=[prompt],
152
- outputs=[result, seed],
153
- cache_examples="lazy",
154
- )
155
 
156
- gr.on(
157
- triggers=[run_button.click, prompt.submit],
158
- fn=generate,
159
- inputs=[prompt, seed, width, height, num_inference_steps],
160
- outputs=[result, seed],
161
- show_api=True,
162
- )
163
 
164
- with gr.Tab("Download Image"):
165
- gr.Markdown("## Download an image from a URL and make it available as a file")
166
- url_input = gr.Text(label="Image URL", placeholder="https://example.com/cool-image.png")
167
- filename_input = gr.Text(
168
- label="Save as (filename)", value="downloaded_image.png", placeholder="downloaded_image.png"
 
 
169
  )
170
- download_btn = gr.Button("Download")
171
- file_output = gr.File(label="Downloaded file")
172
-
173
- download_btn.click(
174
- fn=download_image_locally,
175
- inputs=[url_input, filename_input],
176
- outputs=[file_output],
177
- show_api=True,
 
 
 
 
 
 
 
 
 
 
 
 
 
178
  )
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  if __name__ == "__main__":
181
- demo.launch(mcp_server=True)
 
90
  with gr.Sidebar():
91
  gr.Markdown("# Inference Provider")
92
  gr.Markdown(
93
+ "This Space showcases the blackforestlabs/FLUX.1dev model, served by the nebius API. Sign in with your Hugging Face account to use this API."
94
  )
95
+ gr.LoginButton("Sign in").click(fn=get_token, inputs=[], outputs=[])
 
96
 
97
+ with gr.Column(elem_id="col-container"):
98
+ gr.Markdown(
99
+ """# FLUX.1 [schnell] with fal‑ai through HF Inference Providers ⚡\nLearn more about HF Inference Providers [here](https://huggingface.co/docs/inference-providers/index)"""
100
+ )
 
 
101
 
102
+ with gr.Row():
103
+ prompt = gr.Text(
104
+ label="Prompt",
105
+ show_label=False,
106
+ max_lines=1,
107
+ placeholder="Enter your prompt",
108
+ container=False,
109
+ )
110
+ run_button = gr.Button("Run", scale=0)
111
+
112
+ result = gr.Image(label="Result", show_label=False, format="png")
113
+ download_btn = gr.DownloadButton(
114
+ label="Download result",
115
+ visible=False,
116
+ value=None,
117
+ variant="primary",
118
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
+ seed_number = gr.Number(label="Seed", precision=0, value=42, interactive=False)
 
 
 
 
 
 
121
 
122
+ with gr.Accordion("Advanced Settings", open=False):
123
+ seed_slider = gr.Slider(
124
+ label="Seed",
125
+ minimum=0,
126
+ maximum=MAX_SEED,
127
+ step=1,
128
+ value=42,
129
  )
130
+ with gr.Row():
131
+ width_slider = gr.Slider(
132
+ label="Width",
133
+ minimum=256,
134
+ maximum=MAX_IMAGE_SIZE,
135
+ step=32,
136
+ value=1024,
137
+ )
138
+ height_slider = gr.Slider(
139
+ label="Height",
140
+ minimum=256,
141
+ maximum=MAX_IMAGE_SIZE,
142
+ step=32,
143
+ value=1024,
144
+ )
145
+ steps_slider = gr.Slider(
146
+ label="Number of inference steps",
147
+ minimum=1,
148
+ maximum=50,
149
+ step=1,
150
+ value=25,
151
  )
152
 
153
+ gr.Examples(
154
+ examples=examples,
155
+ fn=generate,
156
+ inputs=[prompt],
157
+ outputs=[result, seed_number, download_btn],
158
+ cache_examples="lazy",
159
+ )
160
+
161
+ run_button.click(
162
+ fn=generate,
163
+ inputs=[prompt, seed_slider, width_slider, height_slider, steps_slider],
164
+ outputs=[result, seed_number, download_btn],
165
+ show_api=True, # expose as MCP tool
166
+ )
167
+
168
+ result.change(
169
+ lambda _: gr.DownloadButton.update(visible=True),
170
+ inputs=[result],
171
+ outputs=[download_btn],
172
+ )
173
+
174
+ gr.Interface(
175
+ fn=download_image_locally,
176
+ inputs=[gr.Text(label="Image URL"), gr.Text(label="Filename")],
177
+ outputs=[gr.File()],
178
+ show_api=True,
179
+ render=False, # do not show in UI
180
+ )
181
+
182
+
183
  if __name__ == "__main__":
184
+ demo.launch(mcp_server=True)