akhaliq HF staff commited on
Commit
3807c9a
1 Parent(s): e98c6cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
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
- stream = client.chat.completions.create(
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=True
66
  )
67
 
68
- # Collect the streamed response
69
- generated_code = ""
70
- for chunk in stream:
71
- if chunk.choices[0].delta.content is not None:
72
- generated_code += chunk.choices[0].delta.content
73
- yield f"Generating Gradio code... (Current length: {len(generated_code)} characters)\n\n{generated_code}"
 
 
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."