Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ import gradio as gr
|
|
| 6 |
import uuid
|
| 7 |
import os
|
| 8 |
|
| 9 |
-
API_KEY = "sk-
|
| 10 |
|
| 11 |
def generate_image(prompt):
|
| 12 |
response = requests.post(
|
|
@@ -28,17 +28,17 @@ def generate_image(prompt):
|
|
| 28 |
if response.status_code != 200:
|
| 29 |
return f"Error: {response.status_code} - {response.text}", None
|
| 30 |
|
| 31 |
-
|
| 32 |
-
b64_image = data["artifacts"][0]["base64"]
|
| 33 |
image_data = base64.b64decode(b64_image)
|
| 34 |
image = Image.open(BytesIO(image_data))
|
| 35 |
|
| 36 |
-
# Save image with a unique
|
| 37 |
filename = f"/tmp/generated_{uuid.uuid4().hex}.png"
|
| 38 |
image.save(filename)
|
| 39 |
|
| 40 |
-
return filename, filename # One for display, one for download
|
| 41 |
|
|
|
|
| 42 |
gr.Interface(
|
| 43 |
fn=generate_image,
|
| 44 |
inputs=gr.Textbox(label="Enter your prompt"),
|
|
|
|
| 6 |
import uuid
|
| 7 |
import os
|
| 8 |
|
| 9 |
+
API_KEY = "sk-k8c1MQmc6OLzrJRs9zJb9ox3VeLmO4Fho7bQo49uLxTX6OTs" # Put your real Stability API key
|
| 10 |
|
| 11 |
def generate_image(prompt):
|
| 12 |
response = requests.post(
|
|
|
|
| 28 |
if response.status_code != 200:
|
| 29 |
return f"Error: {response.status_code} - {response.text}", None
|
| 30 |
|
| 31 |
+
b64_image = response.json()["artifacts"][0]["base64"]
|
|
|
|
| 32 |
image_data = base64.b64decode(b64_image)
|
| 33 |
image = Image.open(BytesIO(image_data))
|
| 34 |
|
| 35 |
+
# Save image to /tmp folder with a unique filename
|
| 36 |
filename = f"/tmp/generated_{uuid.uuid4().hex}.png"
|
| 37 |
image.save(filename)
|
| 38 |
|
| 39 |
+
return filename, filename # One for image display, one for download
|
| 40 |
|
| 41 |
+
# Gradio UI
|
| 42 |
gr.Interface(
|
| 43 |
fn=generate_image,
|
| 44 |
inputs=gr.Textbox(label="Enter your prompt"),
|