try a fix
Browse files
app.py
CHANGED
@@ -34,6 +34,7 @@ def download_image_locally(image_url: str, local_path: str = "downloaded_image.p
|
|
34 |
f.write(response.content)
|
35 |
return local_path
|
36 |
|
|
|
37 |
def login(oauth_token: gr.OAuthToken | None):
|
38 |
global TOKEN
|
39 |
if oauth_token and oauth_token.token:
|
@@ -43,7 +44,8 @@ def login(oauth_token: gr.OAuthToken | None):
|
|
43 |
print("No OAuth token provided, using environment variable HF_TOKEN.")
|
44 |
TOKEN = os.environ.get("HF_TOKEN")
|
45 |
|
46 |
-
|
|
|
47 |
"""
|
48 |
Generate an image from a prompt.
|
49 |
Args:
|
@@ -58,7 +60,7 @@ def generate(prompt: str, seed: int =42, width: int =1024, height: int =1024, nu
|
|
58 |
num_inference_steps (int, default=25):
|
59 |
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
60 |
expense of slower inference.
|
61 |
-
|
62 |
"""
|
63 |
client = InferenceClient(provider="fal-ai", token=TOKEN)
|
64 |
image = client.text_to_image(
|
@@ -67,17 +69,18 @@ def generate(prompt: str, seed: int =42, width: int =1024, height: int =1024, nu
|
|
67 |
height=height,
|
68 |
num_inference_steps=num_inference_steps,
|
69 |
seed=seed,
|
70 |
-
model="black-forest-labs/FLUX.1-dev"
|
71 |
)
|
72 |
return image, seed
|
73 |
-
|
|
|
74 |
examples = [
|
75 |
"a tiny astronaut hatching from an egg on the moon",
|
76 |
"a cat holding a sign that says hello world",
|
77 |
"an anime illustration of a wiener schnitzel",
|
78 |
]
|
79 |
|
80 |
-
css="""
|
81 |
#col-container {
|
82 |
margin: 0 auto;
|
83 |
max-width: 520px;
|
@@ -85,14 +88,12 @@ css="""
|
|
85 |
"""
|
86 |
|
87 |
with gr.Blocks(css=css) as demo:
|
88 |
-
|
89 |
-
|
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 |
-
|
96 |
demo.load(login, inputs=None, outputs=None)
|
97 |
with gr.Column(elem_id="col-container"):
|
98 |
gr.Markdown(
|
@@ -112,7 +113,7 @@ with gr.Blocks(css=css) as demo:
|
|
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 |
)
|
@@ -175,10 +176,8 @@ with gr.Blocks(css=css) as demo:
|
|
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()
|
|
|
34 |
f.write(response.content)
|
35 |
return local_path
|
36 |
|
37 |
+
|
38 |
def login(oauth_token: gr.OAuthToken | None):
|
39 |
global TOKEN
|
40 |
if oauth_token and oauth_token.token:
|
|
|
44 |
print("No OAuth token provided, using environment variable HF_TOKEN.")
|
45 |
TOKEN = os.environ.get("HF_TOKEN")
|
46 |
|
47 |
+
|
48 |
+
def generate(prompt: str, seed: int = 42, width: int = 1024, height: int = 1024, num_inference_steps: int = 25):
|
49 |
"""
|
50 |
Generate an image from a prompt.
|
51 |
Args:
|
|
|
60 |
num_inference_steps (int, default=25):
|
61 |
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
|
62 |
expense of slower inference.
|
63 |
+
|
64 |
"""
|
65 |
client = InferenceClient(provider="fal-ai", token=TOKEN)
|
66 |
image = client.text_to_image(
|
|
|
69 |
height=height,
|
70 |
num_inference_steps=num_inference_steps,
|
71 |
seed=seed,
|
72 |
+
model="black-forest-labs/FLUX.1-dev",
|
73 |
)
|
74 |
return image, seed
|
75 |
+
|
76 |
+
|
77 |
examples = [
|
78 |
"a tiny astronaut hatching from an egg on the moon",
|
79 |
"a cat holding a sign that says hello world",
|
80 |
"an anime illustration of a wiener schnitzel",
|
81 |
]
|
82 |
|
83 |
+
css = """
|
84 |
#col-container {
|
85 |
margin: 0 auto;
|
86 |
max-width: 520px;
|
|
|
88 |
"""
|
89 |
|
90 |
with gr.Blocks(css=css) as demo:
|
|
|
|
|
91 |
with gr.Sidebar():
|
92 |
gr.Markdown("# Inference Provider")
|
93 |
gr.Markdown(
|
94 |
"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."
|
95 |
)
|
96 |
+
|
97 |
demo.load(login, inputs=None, outputs=None)
|
98 |
with gr.Column(elem_id="col-container"):
|
99 |
gr.Markdown(
|
|
|
113 |
result = gr.Image(label="Result", show_label=False, format="png")
|
114 |
download_btn = gr.DownloadButton(
|
115 |
label="Download result",
|
116 |
+
visible=False,
|
117 |
value=None,
|
118 |
variant="primary",
|
119 |
)
|
|
|
176 |
fn=download_image_locally,
|
177 |
inputs=[gr.Text(label="Image URL"), gr.Text(label="Filename")],
|
178 |
outputs=[gr.File()],
|
|
|
|
|
179 |
)
|
180 |
|
181 |
|
182 |
if __name__ == "__main__":
|
183 |
+
demo.launch(mcp_server=True)
|