Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -89,27 +89,33 @@ def enhance_contrast(image):
|
|
89 |
enhanced_image.save(enhanced_path)
|
90 |
return enhanced_path
|
91 |
|
92 |
-
# Function to provide additional suggestions with streaming
|
93 |
def provide_suggestions_streaming(object_identified):
|
94 |
if not object_identified:
|
95 |
-
yield "Sorry, I couldn't
|
96 |
return
|
97 |
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
|
|
|
|
106 |
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
|
|
|
|
|
|
|
|
113 |
|
114 |
# Main image processing function
|
115 |
def process_image(image):
|
|
|
89 |
enhanced_image.save(enhanced_path)
|
90 |
return enhanced_path
|
91 |
|
|
|
92 |
def provide_suggestions_streaming(object_identified):
|
93 |
if not object_identified:
|
94 |
+
yield "⚠️ Sorry, I couldn't identify an object in your artwork. Try uploading a different image."
|
95 |
return
|
96 |
|
97 |
+
try:
|
98 |
+
# Use the OpenAI client for suggestions
|
99 |
+
response = client.chat.completions.create(
|
100 |
+
model="gpt-4o-mini",
|
101 |
+
messages=[
|
102 |
+
{"role": "system", "content": "You are an expert digital art advisor."},
|
103 |
+
{"role": "user", "content": f"Suggest ways to improve a digital artwork featuring a {object_identified}."},
|
104 |
+
],
|
105 |
+
stream=True # Enable streaming
|
106 |
+
)
|
107 |
|
108 |
+
response_text = ""
|
109 |
+
for chunk in response:
|
110 |
+
# Extract the content safely
|
111 |
+
delta = chunk.choices[0].delta # Get the delta object
|
112 |
+
token = getattr(delta, "content", None) # Safely access the "content" field
|
113 |
+
if token: # Only process non-None tokens
|
114 |
+
response_text += token
|
115 |
+
yield response_text
|
116 |
+
|
117 |
+
except Exception as e:
|
118 |
+
yield f"❌ An error occurred while providing suggestions: {str(e)}"
|
119 |
|
120 |
# Main image processing function
|
121 |
def process_image(image):
|