Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,21 +48,28 @@ def generate_art(mood):
|
|
48 |
"inputs": prompt
|
49 |
}
|
50 |
|
51 |
-
response = requests.post('https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5', headers=headers, json=json_data)
|
52 |
|
53 |
-
#
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
# Extract the generated image URL from the response
|
57 |
-
image_url =
|
58 |
|
59 |
# Download the image and return it as a PIL Image
|
60 |
image_response = requests.get(image_url)
|
61 |
image = Image.open(BytesIO(image_response.content))
|
62 |
-
|
63 |
return image
|
64 |
|
65 |
|
|
|
66 |
def mood_art_generator(image):
|
67 |
mood = get_mood_from_image(image)
|
68 |
print("Mood:", mood)
|
|
|
48 |
"inputs": prompt
|
49 |
}
|
50 |
|
51 |
+
response = requests.post('https://api-inference.huggingface.co/models/runwayml/stable-diffusion-v1-5', headers=headers, json=json_data)
|
52 |
|
53 |
+
# Check if the response status is not 200 (OK)
|
54 |
+
if response.status_code != 200:
|
55 |
+
print(f"Error: API response status code {response.status_code}")
|
56 |
+
print("Response content:")
|
57 |
+
print(response.content)
|
58 |
+
return None
|
59 |
+
|
60 |
+
response_json = response.json()
|
61 |
|
62 |
# Extract the generated image URL from the response
|
63 |
+
image_url = response_json["generated_images"][0]["url"]
|
64 |
|
65 |
# Download the image and return it as a PIL Image
|
66 |
image_response = requests.get(image_url)
|
67 |
image = Image.open(BytesIO(image_response.content))
|
68 |
+
|
69 |
return image
|
70 |
|
71 |
|
72 |
+
|
73 |
def mood_art_generator(image):
|
74 |
mood = get_mood_from_image(image)
|
75 |
print("Mood:", mood)
|