Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,17 +15,27 @@ def query_hf_image_generation(api_key, prompt):
|
|
15 |
}
|
16 |
|
17 |
response = requests.post(API_URL, headers=headers, json=data)
|
|
|
|
|
|
|
18 |
result = response.json()
|
19 |
|
|
|
|
|
|
|
20 |
# Check if the API response contains an error.
|
21 |
if 'error' in result:
|
22 |
return "Error: " + result['error'], None
|
23 |
|
24 |
# Assuming the API returns an image in base64 format.
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
|
30 |
iface = gr.Interface(
|
31 |
fn=query_hf_image_generation,
|
|
|
15 |
}
|
16 |
|
17 |
response = requests.post(API_URL, headers=headers, json=data)
|
18 |
+
if response.status_code != 200:
|
19 |
+
return "Error: Unexpected status code {} with message {}".format(response.status_code, response.text)
|
20 |
+
|
21 |
result = response.json()
|
22 |
|
23 |
+
# Debug output to help figure out what result looks like
|
24 |
+
print("DEBUG:", result)
|
25 |
+
|
26 |
# Check if the API response contains an error.
|
27 |
if 'error' in result:
|
28 |
return "Error: " + result['error'], None
|
29 |
|
30 |
# Assuming the API returns an image in base64 format.
|
31 |
+
if 'data' in result:
|
32 |
+
base64_image = result['data'][0] # This might need to be adjusted based on API return structure
|
33 |
+
base64_data = base64_image.split(",")[1] if ',' in base64_image else base64_image
|
34 |
+
image_bytes = base64.b64decode(base64_data)
|
35 |
+
image = Image.open(BytesIO(image_bytes))
|
36 |
+
return image
|
37 |
+
else:
|
38 |
+
return "Error: 'data' not found in response."
|
39 |
|
40 |
iface = gr.Interface(
|
41 |
fn=query_hf_image_generation,
|