Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -38,13 +38,11 @@ def encode_image(image_path):
|
|
| 38 |
def feifeichat(image):
|
| 39 |
try:
|
| 40 |
if image is None:
|
| 41 |
-
|
| 42 |
-
return
|
| 43 |
|
| 44 |
base64_image = encode_image(image)
|
| 45 |
if not base64_image:
|
| 46 |
-
|
| 47 |
-
return
|
| 48 |
|
| 49 |
# Engineered prompt utilizing explicit style rules, forbidden terms, and keyword density targets
|
| 50 |
messages = [
|
|
@@ -65,25 +63,21 @@ def feifeichat(image):
|
|
| 65 |
}
|
| 66 |
]
|
| 67 |
|
| 68 |
-
#
|
| 69 |
response = client.chat.completions.create(
|
| 70 |
model="qwen/qwen3.6-27b",
|
| 71 |
messages=messages,
|
| 72 |
response_format={"type": "json_object"},
|
| 73 |
reasoning_effort="none",
|
| 74 |
temperature=0.7,
|
| 75 |
-
stream=
|
| 76 |
)
|
| 77 |
|
| 78 |
-
|
| 79 |
-
for chunk in response:
|
| 80 |
-
if chunk.choices and chunk.choices[0].delta.content:
|
| 81 |
-
partial_message += chunk.choices[0].delta.content
|
| 82 |
-
yield partial_message
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
print(f"Error: {e}")
|
| 86 |
-
|
| 87 |
|
| 88 |
with gr.Blocks() as demo:
|
| 89 |
gr.Markdown("Image To Flux Prompt")
|
|
|
|
| 38 |
def feifeichat(image):
|
| 39 |
try:
|
| 40 |
if image is None:
|
| 41 |
+
return "Please upload a photo"
|
|
|
|
| 42 |
|
| 43 |
base64_image = encode_image(image)
|
| 44 |
if not base64_image:
|
| 45 |
+
return "Error processing image"
|
|
|
|
| 46 |
|
| 47 |
# Engineered prompt utilizing explicit style rules, forbidden terms, and keyword density targets
|
| 48 |
messages = [
|
|
|
|
| 63 |
}
|
| 64 |
]
|
| 65 |
|
| 66 |
+
# Non-streaming call returns complete JSON payload directly to Gradio API
|
| 67 |
response = client.chat.completions.create(
|
| 68 |
model="qwen/qwen3.6-27b",
|
| 69 |
messages=messages,
|
| 70 |
response_format={"type": "json_object"},
|
| 71 |
reasoning_effort="none",
|
| 72 |
temperature=0.7,
|
| 73 |
+
stream=False
|
| 74 |
)
|
| 75 |
|
| 76 |
+
return response.choices[0].message.content
|
|
|
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
except Exception as e:
|
| 79 |
print(f"Error: {e}")
|
| 80 |
+
return f"An error occurred while processing your request: {e}"
|
| 81 |
|
| 82 |
with gr.Blocks() as demo:
|
| 83 |
gr.Markdown("Image To Flux Prompt")
|