Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -42,7 +42,8 @@ def generate_art(mood):
|
|
42 |
prompt = f"{mood} generative art"
|
43 |
|
44 |
headers = {
|
45 |
-
"Authorization": f"Bearer {STABLE_DIFFUSION_API_KEY}"
|
|
|
46 |
}
|
47 |
|
48 |
json_data = {
|
@@ -58,24 +59,13 @@ def generate_art(mood):
|
|
58 |
print(response.content)
|
59 |
return None
|
60 |
|
61 |
-
|
62 |
-
|
63 |
-
except requests.exceptions.JSONDecodeError:
|
64 |
-
print("Error: Invalid JSON response")
|
65 |
-
print("Response content:")
|
66 |
-
print(response.content)
|
67 |
-
return None
|
68 |
-
|
69 |
-
# Extract the generated image URL from the response
|
70 |
-
image_url = response_json["generated_images"][0]["url"]
|
71 |
-
|
72 |
-
# Download the image and return it as a PIL Image
|
73 |
-
image_response = requests.get(image_url)
|
74 |
-
image = Image.open(BytesIO(image_response.content))
|
75 |
|
76 |
return image
|
77 |
|
78 |
|
|
|
79 |
def mood_art_generator(image):
|
80 |
mood = get_mood_from_image(image)
|
81 |
print("Mood:", mood)
|
|
|
42 |
prompt = f"{mood} generative art"
|
43 |
|
44 |
headers = {
|
45 |
+
"Authorization": f"Bearer {STABLE_DIFFUSION_API_KEY}",
|
46 |
+
"Accept": "image/jpeg", # Set the Accept header to receive an image directly
|
47 |
}
|
48 |
|
49 |
json_data = {
|
|
|
59 |
print(response.content)
|
60 |
return None
|
61 |
|
62 |
+
# Load the image directly from the response content
|
63 |
+
image = Image.open(BytesIO(response.content))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
|
65 |
return image
|
66 |
|
67 |
|
68 |
+
|
69 |
def mood_art_generator(image):
|
70 |
mood = get_mood_from_image(image)
|
71 |
print("Mood:", mood)
|