candenizkocak commited on
Commit
5ae7526
·
verified ·
1 Parent(s): b0fb764

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -14,7 +14,7 @@ def encode_image(image_path):
14
  def run_code(code, groq_api_key):
15
  try:
16
  # Setup Groq API client with the provided API key
17
- llava_client = Groq(api_key=groq_api_key)
18
  llama_client = Groq(api_key=groq_api_key)
19
 
20
  fig, ax = plt.subplots()
@@ -39,9 +39,9 @@ def run_code(code, groq_api_key):
39
  # Encode the image for Groq API
40
  base64_image = encode_image("plot.png")
41
 
42
- # Sending the plot image to LLava API to get the description
43
- llava_completion = llava_client.chat.completions.create(
44
- model="llava-v1.5-7b-4096-preview",
45
  messages=[{
46
  "role": "user",
47
  "content": [
@@ -59,8 +59,8 @@ def run_code(code, groq_api_key):
59
  stop=None,
60
  )
61
 
62
- # Extract the LLava description from the API response
63
- llava_description = llava_completion.choices[0].message.content
64
 
65
  # Sending the plot image to Llama 3.1 API to get the description
66
  llama_completion = llama_client.chat.completions.create(
@@ -87,7 +87,7 @@ def run_code(code, groq_api_key):
87
  for chunk in llama_completion:
88
  llama_description += chunk.choices[0].delta.content or ""
89
 
90
- return img, llava_description, llama_description
91
 
92
  except Exception as e:
93
  return None, f"Error: {str(e)}", None
@@ -115,13 +115,13 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
115
  submit_btn = gr.Button("Submit")
116
 
117
  with gr.Row():
118
- output_llava_text = gr.Textbox(label="Description from LLaVA", interactive=False)
119
  output_llama_text = gr.Textbox(label="Description from Llama 3.1", interactive=False)
120
 
121
  submit_btn.click(
122
  fn=run_code,
123
  inputs=[code_input, api_key_input],
124
- outputs=[output_image, output_llava_text, output_llama_text]
125
  )
126
 
127
  # Launch the interface
 
14
  def run_code(code, groq_api_key):
15
  try:
16
  # Setup Groq API client with the provided API key
17
+ llamavision_client = Groq(api_key=groq_api_key)
18
  llama_client = Groq(api_key=groq_api_key)
19
 
20
  fig, ax = plt.subplots()
 
39
  # Encode the image for Groq API
40
  base64_image = encode_image("plot.png")
41
 
42
+ # Sending the plot image to Llama Vision API to get the description
43
+ llamavision_completion = client.chat.completions.create(
44
+ model="llama-3.2-11b-vision-preview",
45
  messages=[{
46
  "role": "user",
47
  "content": [
 
59
  stop=None,
60
  )
61
 
62
+ # Extract the Llama Vision description from the API response
63
+ llamavision_description = llamavision_completion.choices[0].message.content
64
 
65
  # Sending the plot image to Llama 3.1 API to get the description
66
  llama_completion = llama_client.chat.completions.create(
 
87
  for chunk in llama_completion:
88
  llama_description += chunk.choices[0].delta.content or ""
89
 
90
+ return img, llamavision_description, llama_description
91
 
92
  except Exception as e:
93
  return None, f"Error: {str(e)}", None
 
115
  submit_btn = gr.Button("Submit")
116
 
117
  with gr.Row():
118
+ output_llamavision_text = gr.Textbox(label="Description from Llama 3.2 Vision", interactive=False)
119
  output_llama_text = gr.Textbox(label="Description from Llama 3.1", interactive=False)
120
 
121
  submit_btn.click(
122
  fn=run_code,
123
  inputs=[code_input, api_key_input],
124
+ outputs=[output_image, output_llamavision_text, output_llama_text]
125
  )
126
 
127
  # Launch the interface