Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
import gradio as gr
|
2 |
from openai import OpenAI
|
3 |
|
4 |
# Function to initialize the client with the provided API key
|
@@ -15,6 +15,7 @@ def analyze_environmental_impact(api_key, image=None, location=None, product_inf
|
|
15 |
|
16 |
messages = []
|
17 |
|
|
|
18 |
if image:
|
19 |
messages.append({
|
20 |
"role": "user",
|
@@ -24,12 +25,14 @@ def analyze_environmental_impact(api_key, image=None, location=None, product_inf
|
|
24 |
]
|
25 |
})
|
26 |
|
|
|
27 |
if location:
|
28 |
messages.append({
|
29 |
"role": "user",
|
30 |
"content": [{"type": "text", "text": f"Analyze the environmental impact of {location}."}]
|
31 |
})
|
32 |
|
|
|
33 |
if product_info:
|
34 |
messages.append({
|
35 |
"role": "user",
|
@@ -55,12 +58,12 @@ def analyze_environmental_impact(api_key, image=None, location=None, product_inf
|
|
55 |
|
56 |
# Gradio interface
|
57 |
def gradio_interface(api_key, image, location, product_info):
|
58 |
-
image_url = image if image else None #
|
59 |
-
result = analyze_environmental_impact(api_key,
|
60 |
return result
|
61 |
|
62 |
# Create Gradio inputs and outputs
|
63 |
-
api_key_input = gr.Textbox(label="Enter Your OpenRouter API Key", type="
|
64 |
image_input = gr.Image(label="Upload an Image (Optional)", type="filepath") # Fix: Changed to 'filepath'
|
65 |
location_input = gr.Textbox(label="Enter Location for Environmental Impact (Optional)", type="text")
|
66 |
product_info_input = gr.Textbox(label="Enter Product Information (Optional)", type="text")
|
|
|
1 |
+
import gradio as gr
|
2 |
from openai import OpenAI
|
3 |
|
4 |
# Function to initialize the client with the provided API key
|
|
|
15 |
|
16 |
messages = []
|
17 |
|
18 |
+
# If the image is provided, include it in the analysis
|
19 |
if image:
|
20 |
messages.append({
|
21 |
"role": "user",
|
|
|
25 |
]
|
26 |
})
|
27 |
|
28 |
+
# If location is provided, include it in the analysis
|
29 |
if location:
|
30 |
messages.append({
|
31 |
"role": "user",
|
32 |
"content": [{"type": "text", "text": f"Analyze the environmental impact of {location}."}]
|
33 |
})
|
34 |
|
35 |
+
# If product information is provided, include it in the analysis
|
36 |
if product_info:
|
37 |
messages.append({
|
38 |
"role": "user",
|
|
|
58 |
|
59 |
# Gradio interface
|
60 |
def gradio_interface(api_key, image, location, product_info):
|
61 |
+
image_url = image if image else None # Gradio returns file path as string for "filepath" type
|
62 |
+
result = analyze_environmental_impact(api_key, image=image_url, location=location, product_info=product_info)
|
63 |
return result
|
64 |
|
65 |
# Create Gradio inputs and outputs
|
66 |
+
api_key_input = gr.Textbox(label="Enter Your OpenRouter API Key", type="text")
|
67 |
image_input = gr.Image(label="Upload an Image (Optional)", type="filepath") # Fix: Changed to 'filepath'
|
68 |
location_input = gr.Textbox(label="Enter Location for Environmental Impact (Optional)", type="text")
|
69 |
product_info_input = gr.Textbox(label="Enter Product Information (Optional)", type="text")
|