Spaces:
Build error
Build error
AppleBotzz
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ def get_media_type(image_name):
|
|
21 |
else:
|
22 |
return None # Extend this function based on the image formats you expect to handle
|
23 |
|
24 |
-
def describe_image(image_path, api_key, model):
|
25 |
"""Send the image to Claude for description."""
|
26 |
image_base64 = image_to_base64(image_path)
|
27 |
media_type = get_media_type(image_path)
|
@@ -44,7 +44,7 @@ def describe_image(image_path, api_key, model):
|
|
44 |
},
|
45 |
{
|
46 |
"type": "text",
|
47 |
-
"text":
|
48 |
}
|
49 |
],
|
50 |
}
|
@@ -52,10 +52,10 @@ def describe_image(image_path, api_key, model):
|
|
52 |
)
|
53 |
return message.content
|
54 |
|
55 |
-
def main(image_path, api_key, model_a, model_b):
|
56 |
if api_key:
|
57 |
-
description_a = describe_image(image_path, api_key, model_a)
|
58 |
-
description_b = describe_image(image_path, api_key, model_b)
|
59 |
|
60 |
if isinstance(description_a, list) and len(description_a) > 0:
|
61 |
description_a = description_a[0].text
|
@@ -81,20 +81,21 @@ with gr.Blocks() as iface:
|
|
81 |
with gr.Column():
|
82 |
image_input = gr.Image(type="filepath", label="Upload Image")
|
83 |
api_key_input = gr.Textbox(type="password", label="Enter your Claude API Key")
|
84 |
-
run_button = gr.Button("Run")
|
85 |
|
86 |
with gr.Column():
|
87 |
-
|
88 |
-
|
89 |
-
model_b_dropdown = gr.Dropdown(choices=model_options, label="Model B")
|
90 |
|
91 |
with gr.Row():
|
92 |
output_a = gr.Textbox(label="Description from Model A")
|
93 |
output_b = gr.Textbox(label="Description from Model B")
|
94 |
|
|
|
|
|
|
|
95 |
run_button.click(
|
96 |
fn=main,
|
97 |
-
inputs=[image_input, api_key_input, model_a_dropdown, model_b_dropdown],
|
98 |
outputs=[output_a, output_b]
|
99 |
)
|
100 |
|
|
|
21 |
else:
|
22 |
return None # Extend this function based on the image formats you expect to handle
|
23 |
|
24 |
+
def describe_image(image_path, api_key, model, prompt):
|
25 |
"""Send the image to Claude for description."""
|
26 |
image_base64 = image_to_base64(image_path)
|
27 |
media_type = get_media_type(image_path)
|
|
|
44 |
},
|
45 |
{
|
46 |
"type": "text",
|
47 |
+
"text": prompt
|
48 |
}
|
49 |
],
|
50 |
}
|
|
|
52 |
)
|
53 |
return message.content
|
54 |
|
55 |
+
def main(image_path, api_key, model_a, model_b, prompt):
|
56 |
if api_key:
|
57 |
+
description_a = describe_image(image_path, api_key, model_a, prompt)
|
58 |
+
description_b = describe_image(image_path, api_key, model_b, prompt)
|
59 |
|
60 |
if isinstance(description_a, list) and len(description_a) > 0:
|
61 |
description_a = description_a[0].text
|
|
|
81 |
with gr.Column():
|
82 |
image_input = gr.Image(type="filepath", label="Upload Image")
|
83 |
api_key_input = gr.Textbox(type="password", label="Enter your Claude API Key")
|
|
|
84 |
|
85 |
with gr.Column():
|
86 |
+
model_a_dropdown = gr.Dropdown(choices=model_options, label="Model A")
|
87 |
+
model_b_dropdown = gr.Dropdown(choices=model_options, label="Model B")
|
|
|
88 |
|
89 |
with gr.Row():
|
90 |
output_a = gr.Textbox(label="Description from Model A")
|
91 |
output_b = gr.Textbox(label="Description from Model B")
|
92 |
|
93 |
+
prompt_input = gr.Textbox(label="Custom Prompt", value="Describe this image.")
|
94 |
+
run_button = gr.Button("Run")
|
95 |
+
|
96 |
run_button.click(
|
97 |
fn=main,
|
98 |
+
inputs=[image_input, api_key_input, model_a_dropdown, model_b_dropdown, prompt_input],
|
99 |
outputs=[output_a, output_b]
|
100 |
)
|
101 |
|