Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import io
|
|
4 |
from PIL import Image
|
5 |
from together import Together
|
6 |
|
7 |
-
def generate_image(api_key, prompt):
|
8 |
try:
|
9 |
# Initialize the Together AI client with the provided API key
|
10 |
client = Together(api_key=api_key)
|
@@ -13,9 +13,9 @@ def generate_image(api_key, prompt):
|
|
13 |
response = client.images.generate(
|
14 |
prompt=prompt,
|
15 |
model="black-forest-labs/FLUX.1-schnell-Free",
|
16 |
-
width=
|
17 |
-
height=
|
18 |
-
steps=
|
19 |
n=1,
|
20 |
response_format="b64_json"
|
21 |
)
|
@@ -37,7 +37,7 @@ with gr.Blocks() as app:
|
|
37 |
gr.Markdown("Generate images using the FLUX.1-schnell-Free model from Together AI")
|
38 |
|
39 |
with gr.Row():
|
40 |
-
with gr.Column():
|
41 |
api_key_input = gr.Textbox(
|
42 |
label="Together API Key",
|
43 |
placeholder="Enter your Together API key here...",
|
@@ -48,23 +48,50 @@ with gr.Blocks() as app:
|
|
48 |
placeholder="A beautiful sunset over mountains...",
|
49 |
lines=3
|
50 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
generate_button = gr.Button("Generate Image")
|
52 |
|
53 |
-
with gr.Column():
|
54 |
image_output = gr.Image(label="Generated Image")
|
55 |
|
56 |
generate_button.click(
|
57 |
fn=generate_image,
|
58 |
-
inputs=[api_key_input, prompt_input],
|
59 |
outputs=image_output
|
60 |
)
|
61 |
|
62 |
gr.Markdown("""
|
63 |
## Instructions
|
64 |
-
1. Enter your Together
|
65 |
2. Enter a descriptive prompt in the text box
|
66 |
-
3.
|
67 |
-
|
|
|
|
|
|
|
68 |
|
69 |
Note: Your API key is not stored and is only used for the current session.
|
70 |
""")
|
|
|
4 |
from PIL import Image
|
5 |
from together import Together
|
6 |
|
7 |
+
def generate_image(api_key, prompt, width, height, steps):
|
8 |
try:
|
9 |
# Initialize the Together AI client with the provided API key
|
10 |
client = Together(api_key=api_key)
|
|
|
13 |
response = client.images.generate(
|
14 |
prompt=prompt,
|
15 |
model="black-forest-labs/FLUX.1-schnell-Free",
|
16 |
+
width=width,
|
17 |
+
height=height,
|
18 |
+
steps=steps,
|
19 |
n=1,
|
20 |
response_format="b64_json"
|
21 |
)
|
|
|
37 |
gr.Markdown("Generate images using the FLUX.1-schnell-Free model from Together AI")
|
38 |
|
39 |
with gr.Row():
|
40 |
+
with gr.Column(scale=1):
|
41 |
api_key_input = gr.Textbox(
|
42 |
label="Together API Key",
|
43 |
placeholder="Enter your Together API key here...",
|
|
|
48 |
placeholder="A beautiful sunset over mountains...",
|
49 |
lines=3
|
50 |
)
|
51 |
+
|
52 |
+
with gr.Row():
|
53 |
+
width_input = gr.Number(
|
54 |
+
label="Width",
|
55 |
+
value=1024,
|
56 |
+
min=256,
|
57 |
+
max=2048,
|
58 |
+
step=64
|
59 |
+
)
|
60 |
+
height_input = gr.Number(
|
61 |
+
label="Height",
|
62 |
+
value=768,
|
63 |
+
min=256,
|
64 |
+
max=2048,
|
65 |
+
step=64
|
66 |
+
)
|
67 |
+
steps_input = gr.Slider(
|
68 |
+
label="Steps",
|
69 |
+
minimum=1,
|
70 |
+
maximum=50,
|
71 |
+
value=4,
|
72 |
+
step=1
|
73 |
+
)
|
74 |
+
|
75 |
generate_button = gr.Button("Generate Image")
|
76 |
|
77 |
+
with gr.Column(scale=1):
|
78 |
image_output = gr.Image(label="Generated Image")
|
79 |
|
80 |
generate_button.click(
|
81 |
fn=generate_image,
|
82 |
+
inputs=[api_key_input, prompt_input, width_input, height_input, steps_input],
|
83 |
outputs=image_output
|
84 |
)
|
85 |
|
86 |
gr.Markdown("""
|
87 |
## Instructions
|
88 |
+
1. Enter your Together API Key (get one from https://www.together.ai)
|
89 |
2. Enter a descriptive prompt in the text box
|
90 |
+
3. Adjust the width, height, and steps as needed
|
91 |
+
- Width and height control the dimensions of the generated image
|
92 |
+
- Steps control the number of diffusion steps (higher = more detail but slower)
|
93 |
+
4. Click "Generate Image"
|
94 |
+
5. Wait for the image to be generated
|
95 |
|
96 |
Note: Your API key is not stored and is only used for the current session.
|
97 |
""")
|