Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,7 +38,7 @@ def feifeichat(image):
|
|
| 38 |
if image is None:
|
| 39 |
yield "Please upload a photo"
|
| 40 |
return
|
| 41 |
-
|
| 42 |
base64_image = encode_image(image)
|
| 43 |
if not base64_image:
|
| 44 |
yield "Error processing image"
|
|
@@ -49,7 +49,10 @@ def feifeichat(image):
|
|
| 49 |
{
|
| 50 |
"role": "user",
|
| 51 |
"content": [
|
| 52 |
-
{
|
|
|
|
|
|
|
|
|
|
| 53 |
{
|
| 54 |
"type": "image_url",
|
| 55 |
"image_url": {
|
|
@@ -59,19 +62,21 @@ def feifeichat(image):
|
|
| 59 |
]
|
| 60 |
}
|
| 61 |
]
|
| 62 |
-
|
|
|
|
| 63 |
response = client.chat.completions.create(
|
| 64 |
model="meta-llama/llama-4-scout-17b-16e-instruct",
|
| 65 |
messages=messages,
|
|
|
|
| 66 |
stream=True
|
| 67 |
)
|
| 68 |
-
|
| 69 |
partial_message = ""
|
| 70 |
for chunk in response:
|
| 71 |
if chunk.choices and chunk.choices[0].delta.content:
|
| 72 |
partial_message += chunk.choices[0].delta.content
|
| 73 |
yield partial_message
|
| 74 |
-
|
| 75 |
except Exception as e:
|
| 76 |
print(f"Error: {e}")
|
| 77 |
yield "An error occurred while processing your request"
|
|
|
|
| 38 |
if image is None:
|
| 39 |
yield "Please upload a photo"
|
| 40 |
return
|
| 41 |
+
|
| 42 |
base64_image = encode_image(image)
|
| 43 |
if not base64_image:
|
| 44 |
yield "Error processing image"
|
|
|
|
| 49 |
{
|
| 50 |
"role": "user",
|
| 51 |
"content": [
|
| 52 |
+
{
|
| 53 |
+
"type": "text",
|
| 54 |
+
"text": "Analyze the image and return strictly valid JSON format with keys 'title', 'description', 'meta_title' (max 60 chars), 'meta_description' (max 155 chars), 'tags' (array of 5-8 strings), 'style_breakdown' (object with keys: aesthetic, top, bottom, legwear, accessories), and 'faqs' (array of two objects with 'q' and 'a'), focusing on youthfulness, cute/sexy style, and legwear, with no code blocks or intro text."
|
| 55 |
+
},
|
| 56 |
{
|
| 57 |
"type": "image_url",
|
| 58 |
"image_url": {
|
|
|
|
| 62 |
]
|
| 63 |
}
|
| 64 |
]
|
| 65 |
+
|
| 66 |
+
# response_format forcing JSON mode guarantees error-free data structural rendering
|
| 67 |
response = client.chat.completions.create(
|
| 68 |
model="meta-llama/llama-4-scout-17b-16e-instruct",
|
| 69 |
messages=messages,
|
| 70 |
+
response_format={"type": "json_object"},
|
| 71 |
stream=True
|
| 72 |
)
|
| 73 |
+
|
| 74 |
partial_message = ""
|
| 75 |
for chunk in response:
|
| 76 |
if chunk.choices and chunk.choices[0].delta.content:
|
| 77 |
partial_message += chunk.choices[0].delta.content
|
| 78 |
yield partial_message
|
| 79 |
+
|
| 80 |
except Exception as e:
|
| 81 |
print(f"Error: {e}")
|
| 82 |
yield "An error occurred while processing your request"
|