better?
Browse files
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
|
| 94 |
)
|
| 95 |
-
|
| 96 |
-
button.click(fn=get_token, inputs=[], outputs=[])
|
| 97 |
|
| 98 |
-
with gr.
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 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 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 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 |
-
|
| 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.
|
| 165 |
-
gr.
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
|
|
|
|
|
|
| 169 |
)
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 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 |
+
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)
|