Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ from io import BytesIO
|
|
| 5 |
from PIL import Image
|
| 6 |
import numpy as np
|
| 7 |
import traceback
|
|
|
|
| 8 |
|
| 9 |
def generate_gradio_app(api_key, image):
|
| 10 |
if not api_key:
|
|
@@ -40,7 +41,7 @@ def generate_gradio_app(api_key, image):
|
|
| 40 |
Please generate the entire Gradio code based on the provided image."""
|
| 41 |
|
| 42 |
# Make the API call
|
| 43 |
-
|
| 44 |
model="meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
|
| 45 |
messages=[
|
| 46 |
{
|
|
@@ -62,15 +63,17 @@ Please generate the entire Gradio code based on the provided image."""
|
|
| 62 |
top_k=50,
|
| 63 |
repetition_penalty=1,
|
| 64 |
stop=["<|eot_id|>", "<|eom_id|>"],
|
| 65 |
-
stream=
|
| 66 |
)
|
| 67 |
|
| 68 |
-
#
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
|
|
|
| 74 |
|
| 75 |
if not generated_code:
|
| 76 |
return "Error: No code generated from the model. Please try again."
|
|
|
|
| 5 |
from PIL import Image
|
| 6 |
import numpy as np
|
| 7 |
import traceback
|
| 8 |
+
import json
|
| 9 |
|
| 10 |
def generate_gradio_app(api_key, image):
|
| 11 |
if not api_key:
|
|
|
|
| 41 |
Please generate the entire Gradio code based on the provided image."""
|
| 42 |
|
| 43 |
# Make the API call
|
| 44 |
+
response = client.chat.completions.create(
|
| 45 |
model="meta-llama/Llama-3.2-90B-Vision-Instruct-Turbo",
|
| 46 |
messages=[
|
| 47 |
{
|
|
|
|
| 63 |
top_k=50,
|
| 64 |
repetition_penalty=1,
|
| 65 |
stop=["<|eot_id|>", "<|eom_id|>"],
|
| 66 |
+
stream=False # Changed to False for easier debugging
|
| 67 |
)
|
| 68 |
|
| 69 |
+
# Debug: Print the entire response
|
| 70 |
+
print("API Response:", json.dumps(response, indent=2))
|
| 71 |
+
|
| 72 |
+
# Extract the generated code from the response
|
| 73 |
+
if response.choices and response.choices[0].message:
|
| 74 |
+
generated_code = response.choices[0].message.content
|
| 75 |
+
else:
|
| 76 |
+
return "Error: Unexpected response structure from the API."
|
| 77 |
|
| 78 |
if not generated_code:
|
| 79 |
return "Error: No code generated from the model. Please try again."
|