Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
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
|
43 |
-
|
44 |
-
model="
|
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
|
63 |
-
|
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,
|
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 |
-
|
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,
|
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
|