shukdevdatta123 commited on
Commit
3897b29
·
verified ·
1 Parent(s): 1369577

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -10,17 +10,17 @@ def initialize_client(api_key):
10
  return client
11
 
12
  # Function to analyze environmental impact using Gemini 2.5 Pro
13
- def analyze_environmental_impact(api_key, image_url=None, location=None, product_info=None):
14
  client = initialize_client(api_key) # Initialize client with the user's API key
15
 
16
  messages = []
17
 
18
- if image_url:
19
  messages.append({
20
  "role": "user",
21
  "content": [
22
  {"type": "text", "text": "Analyze the environmental impact of this image."},
23
- {"type": "image_url", "image_url": {"url": image_url}}
24
  ]
25
  })
26
 
@@ -55,13 +55,13 @@ def analyze_environmental_impact(api_key, image_url=None, location=None, product
55
 
56
  # Gradio interface
57
  def gradio_interface(api_key, image, location, product_info):
58
- image_url = image.name if image else None
59
  result = analyze_environmental_impact(api_key, image_url=image_url, location=location, product_info=product_info)
60
  return result
61
 
62
  # Create Gradio inputs and outputs
63
  api_key_input = gr.Textbox(label="Enter Your OpenRouter API Key", type="text")
64
- image_input = gr.Image(label="Upload an Image (Optional)", type="file")
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")
67
 
 
10
  return client
11
 
12
  # Function to analyze environmental impact using Gemini 2.5 Pro
13
+ def analyze_environmental_impact(api_key, image=None, location=None, product_info=None):
14
  client = initialize_client(api_key) # Initialize client with the user's API key
15
 
16
  messages = []
17
 
18
+ if image:
19
  messages.append({
20
  "role": "user",
21
  "content": [
22
  {"type": "text", "text": "Analyze the environmental impact of this image."},
23
+ {"type": "image_url", "image_url": {"url": image}}
24
  ]
25
  })
26
 
 
55
 
56
  # Gradio interface
57
  def gradio_interface(api_key, image, location, product_info):
58
+ image_url = image if image else None # For filepath, Gradio returns the path of the uploaded image
59
  result = analyze_environmental_impact(api_key, image_url=image_url, location=location, product_info=product_info)
60
  return result
61
 
62
  # Create Gradio inputs and outputs
63
  api_key_input = gr.Textbox(label="Enter Your OpenRouter API Key", type="text")
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")
67