Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -4,11 +4,11 @@ import io
|
|
4 |
from PIL import Image
|
5 |
from together import Together
|
6 |
|
7 |
-
|
8 |
-
client = Together()
|
9 |
-
|
10 |
-
def generate_image(prompt):
|
11 |
try:
|
|
|
|
|
|
|
12 |
# Call the Together API to generate an image
|
13 |
response = client.images.generate(
|
14 |
prompt=prompt,
|
@@ -38,6 +38,11 @@ with gr.Blocks() as app:
|
|
38 |
|
39 |
with gr.Row():
|
40 |
with gr.Column():
|
|
|
|
|
|
|
|
|
|
|
41 |
prompt_input = gr.Textbox(
|
42 |
label="Enter your prompt",
|
43 |
placeholder="A beautiful sunset over mountains...",
|
@@ -50,18 +55,18 @@ with gr.Blocks() as app:
|
|
50 |
|
51 |
generate_button.click(
|
52 |
fn=generate_image,
|
53 |
-
inputs=prompt_input,
|
54 |
outputs=image_output
|
55 |
)
|
56 |
|
57 |
gr.Markdown("""
|
58 |
## Instructions
|
59 |
-
1. Enter
|
60 |
-
2.
|
61 |
-
3.
|
|
|
62 |
|
63 |
-
Note:
|
64 |
-
usually through environment variables or a config file.
|
65 |
""")
|
66 |
|
67 |
# Launch the app
|
|
|
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)
|
11 |
+
|
12 |
# Call the Together API to generate an image
|
13 |
response = client.images.generate(
|
14 |
prompt=prompt,
|
|
|
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...",
|
44 |
+
type="password" # Mask the API key for security
|
45 |
+
)
|
46 |
prompt_input = gr.Textbox(
|
47 |
label="Enter your prompt",
|
48 |
placeholder="A beautiful sunset over mountains...",
|
|
|
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 AI API key (get one from https://www.together.ai)
|
65 |
+
2. Enter a descriptive prompt in the text box
|
66 |
+
3. Click "Generate Image"
|
67 |
+
4. Wait for the image to be generated
|
68 |
|
69 |
+
Note: Your API key is not stored and is only used for the current session.
|
|
|
70 |
""")
|
71 |
|
72 |
# Launch the app
|