Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,99 +1,100 @@
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
|
|
3 |
|
4 |
-
# Initialize the
|
5 |
client = Client("ByteDance/Hyper-FLUX-8Steps-LoRA")
|
6 |
|
7 |
-
def generate_image(prompt, height, width, steps,
|
8 |
"""
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
Returns:
|
20 |
-
|
21 |
"""
|
|
|
|
|
|
|
|
|
22 |
try:
|
23 |
-
# Call the predict method of the client with provided parameters
|
24 |
result = client.predict(
|
25 |
-
height=height,
|
26 |
-
width=width,
|
27 |
-
steps=steps,
|
28 |
-
scales=
|
29 |
prompt=prompt,
|
30 |
-
seed=seed,
|
31 |
api_name="/process_image"
|
32 |
)
|
33 |
return result
|
34 |
except Exception as e:
|
35 |
return f"An error occurred: {e}"
|
36 |
|
37 |
-
# Define the Gradio interface
|
38 |
with gr.Blocks() as demo:
|
39 |
gr.Markdown("# Hyper-FLUX-8Steps-LoRA Image Generator")
|
40 |
-
gr.Markdown(
|
41 |
-
|
42 |
-
Enter a text prompt and adjust the parameters to generate an image using the Hyper-FLUX-8Steps-LoRA model.
|
43 |
-
"""
|
44 |
-
)
|
45 |
-
|
46 |
with gr.Row():
|
47 |
with gr.Column():
|
48 |
prompt = gr.Textbox(
|
49 |
label="Prompt",
|
50 |
-
placeholder="Enter your
|
51 |
lines=2
|
52 |
)
|
53 |
-
height = gr.
|
54 |
label="Height",
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
value=1024
|
59 |
)
|
60 |
-
width = gr.
|
61 |
label="Width",
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
value=1024
|
66 |
)
|
67 |
-
steps = gr.
|
68 |
label="Steps",
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
value=8
|
73 |
)
|
74 |
-
|
75 |
label="Scale",
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
value=3.5
|
80 |
)
|
81 |
seed = gr.Number(
|
82 |
label="Seed",
|
83 |
value=3413,
|
84 |
-
precision=0
|
|
|
85 |
)
|
86 |
-
|
87 |
-
|
88 |
with gr.Column():
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
92 |
fn=generate_image,
|
93 |
-
inputs=[prompt, height, width, steps,
|
94 |
-
outputs=
|
95 |
)
|
96 |
|
|
|
|
|
|
|
97 |
# Launch the Gradio app
|
98 |
if __name__ == "__main__":
|
99 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from gradio_client import Client
|
3 |
+
import random
|
4 |
|
5 |
+
# Initialize the client for the Hugging Face Space
|
6 |
client = Client("ByteDance/Hyper-FLUX-8Steps-LoRA")
|
7 |
|
8 |
+
def generate_image(prompt, height, width, steps, scales, seed):
|
9 |
"""
|
10 |
+
Generates an image based on the provided parameters by calling the Hugging Face Space API.
|
11 |
+
|
12 |
+
Parameters:
|
13 |
+
- prompt (str): The text prompt for image generation.
|
14 |
+
- height (int): The height of the generated image.
|
15 |
+
- width (int): The width of the generated image.
|
16 |
+
- steps (int): The number of steps for the image generation process.
|
17 |
+
- scales (float): The scaling factor.
|
18 |
+
- seed (int): The seed for random number generation to ensure reproducibility.
|
19 |
+
|
20 |
Returns:
|
21 |
+
- result (str or Image): The generated image or a link to it.
|
22 |
"""
|
23 |
+
# Generate a random seed if not provided
|
24 |
+
if not seed:
|
25 |
+
seed = random.randint(0, 100000)
|
26 |
+
|
27 |
try:
|
|
|
28 |
result = client.predict(
|
29 |
+
height=int(height),
|
30 |
+
width=int(width),
|
31 |
+
steps=int(steps),
|
32 |
+
scales=float(scales),
|
33 |
prompt=prompt,
|
34 |
+
seed=int(seed),
|
35 |
api_name="/process_image"
|
36 |
)
|
37 |
return result
|
38 |
except Exception as e:
|
39 |
return f"An error occurred: {e}"
|
40 |
|
41 |
+
# Define the Gradio interface
|
42 |
with gr.Blocks() as demo:
|
43 |
gr.Markdown("# Hyper-FLUX-8Steps-LoRA Image Generator")
|
44 |
+
gr.Markdown("Generate images based on your text prompts using the Hyper-FLUX-8Steps-LoRA model.")
|
45 |
+
|
|
|
|
|
|
|
|
|
46 |
with gr.Row():
|
47 |
with gr.Column():
|
48 |
prompt = gr.Textbox(
|
49 |
label="Prompt",
|
50 |
+
placeholder="Enter your descriptive text here...",
|
51 |
lines=2
|
52 |
)
|
53 |
+
height = gr.Number(
|
54 |
label="Height",
|
55 |
+
value=1024,
|
56 |
+
precision=0,
|
57 |
+
interactive=True
|
|
|
58 |
)
|
59 |
+
width = gr.Number(
|
60 |
label="Width",
|
61 |
+
value=1024,
|
62 |
+
precision=0,
|
63 |
+
interactive=True
|
|
|
64 |
)
|
65 |
+
steps = gr.Number(
|
66 |
label="Steps",
|
67 |
+
value=8,
|
68 |
+
precision=0,
|
69 |
+
interactive=True
|
|
|
70 |
)
|
71 |
+
scales = gr.Number(
|
72 |
label="Scale",
|
73 |
+
value=3.5,
|
74 |
+
precision=1,
|
75 |
+
interactive=True
|
|
|
76 |
)
|
77 |
seed = gr.Number(
|
78 |
label="Seed",
|
79 |
value=3413,
|
80 |
+
precision=0,
|
81 |
+
interactive=True
|
82 |
)
|
83 |
+
generate_button = gr.Button("Generate Image")
|
84 |
+
|
85 |
with gr.Column():
|
86 |
+
output_image = gr.Image(label="Generated Image", interactive=False)
|
87 |
+
|
88 |
+
# Define the button click action
|
89 |
+
generate_button.click(
|
90 |
fn=generate_image,
|
91 |
+
inputs=[prompt, height, width, steps, scales, seed],
|
92 |
+
outputs=output_image
|
93 |
)
|
94 |
|
95 |
+
# Optional: Add a footer or additional information
|
96 |
+
gr.Markdown("© 2024 Your Name. All rights reserved.")
|
97 |
+
|
98 |
# Launch the Gradio app
|
99 |
if __name__ == "__main__":
|
100 |
demo.launch()
|