Spaces:
Runtime error
Runtime error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -4,18 +4,29 @@ import base64
|
|
| 4 |
from PIL import Image
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
-
API_URL = "https://
|
| 8 |
|
| 9 |
|
| 10 |
def generate(prompt, seed):
|
| 11 |
response = requests.post(
|
| 12 |
API_URL,
|
| 13 |
-
json={
|
|
|
|
|
|
|
| 14 |
)
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
image = Image.open(BytesIO(img_bytes))
|
| 20 |
|
| 21 |
return image
|
|
|
|
| 4 |
from PIL import Image
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
+
API_URL = "https://florafeng-uclip-img-gen.hf.space/run/predict"
|
| 8 |
|
| 9 |
|
| 10 |
def generate(prompt, seed):
|
| 11 |
response = requests.post(
|
| 12 |
API_URL,
|
| 13 |
+
json={
|
| 14 |
+
"data": [prompt, int(seed)]
|
| 15 |
+
}
|
| 16 |
)
|
| 17 |
|
| 18 |
+
if response.status_code != 200:
|
| 19 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 20 |
|
| 21 |
+
try:
|
| 22 |
+
data = response.json()
|
| 23 |
+
except Exception:
|
| 24 |
+
return f"Invalid JSON response: {response.text}"
|
| 25 |
+
|
| 26 |
+
# Gradio responses are usually in: data["data"]
|
| 27 |
+
img_base64 = data["data"][0]
|
| 28 |
+
|
| 29 |
+
img_bytes = base64.b64decode(img_base64)
|
| 30 |
image = Image.open(BytesIO(img_bytes))
|
| 31 |
|
| 32 |
return image
|