Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -58,38 +58,25 @@ def generate_art(mood):
|
|
58 |
print(response.content)
|
59 |
return None
|
60 |
|
61 |
-
try: # Add a try-except block to handle JSONDecodeError
|
62 |
-
response_json = response.json()
|
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(
|
74 |
image = Image.open(BytesIO(image_response.content))
|
75 |
|
76 |
return image
|
77 |
|
78 |
-
|
79 |
-
|
80 |
def mood_art_generator(image):
|
81 |
mood = get_mood_from_image(image)
|
82 |
print("Mood:", mood)
|
83 |
if mood:
|
84 |
art = generate_art(mood)
|
85 |
-
return
|
86 |
else:
|
87 |
return None
|
88 |
|
89 |
iface = gr.Interface(
|
90 |
fn=mood_art_generator,
|
91 |
inputs=gr.inputs.Image(shape=(224, 224), image_mode="RGB", source="upload"),
|
92 |
-
outputs=gr.outputs.Image(
|
93 |
title="Mood-based Art Generator",
|
94 |
description="Upload an image of yourself and let the AI generate artwork based on your mood.",
|
95 |
allow_flagging=False,
|
|
|
58 |
print(response.content)
|
59 |
return None
|
60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
61 |
# Download the image and return it as a PIL Image
|
62 |
+
image_response = requests.get(response.url)
|
63 |
image = Image.open(BytesIO(image_response.content))
|
64 |
|
65 |
return image
|
66 |
|
|
|
|
|
67 |
def mood_art_generator(image):
|
68 |
mood = get_mood_from_image(image)
|
69 |
print("Mood:", mood)
|
70 |
if mood:
|
71 |
art = generate_art(mood)
|
72 |
+
return art
|
73 |
else:
|
74 |
return None
|
75 |
|
76 |
iface = gr.Interface(
|
77 |
fn=mood_art_generator,
|
78 |
inputs=gr.inputs.Image(shape=(224, 224), image_mode="RGB", source="upload"),
|
79 |
+
outputs=gr.outputs.Image(shape=(200, 200), source="image", pilmode="RGB"),
|
80 |
title="Mood-based Art Generator",
|
81 |
description="Upload an image of yourself and let the AI generate artwork based on your mood.",
|
82 |
allow_flagging=False,
|