shukdevdatta123 commited on
Commit
bc8a428
·
verified ·
1 Parent(s): 6a66e6f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -58
app.py CHANGED
@@ -178,57 +178,45 @@ with gr.Blocks(title="Smart Environmental Impact Analyzer") as app:
178
 
179
  api_key = gr.Textbox(label="OpenRouter API Key", placeholder="Enter your OpenRouter API key", type="password")
180
 
181
- # Create inputs for each analysis type
182
- image_input = gr.Image(type="pil", visible=False)
183
- text_input = gr.Textbox(visible=False)
184
- location_input = gr.Textbox(visible=False)
185
- product_input = gr.Textbox(visible=False)
186
-
187
  with gr.Tabs():
188
  with gr.TabItem("Image Analysis"):
189
- image_input_tab = gr.Image(type="pil", label="Upload an image for environmental analysis")
190
  image_submit = gr.Button("Analyze Image")
191
  image_output = gr.Textbox(label="Analysis Results", lines=15)
192
 
193
- def process_image_tab():
194
- return analyze_environmental_impact(
195
- api_key.value,
196
- "Image Analysis",
197
- image=image_input_tab.value,
198
- text_input=None,
199
- location=None,
200
- product_info=None
201
- )
202
-
203
  image_submit.click(
204
- fn=process_image_tab,
205
- inputs=None,
 
 
 
 
 
 
 
206
  outputs=image_output
207
  )
208
 
209
  with gr.TabItem("Geographical Assessment"):
210
- location_input_tab = gr.Textbox(label="Location (city, region, or country)", placeholder="e.g., Paris, France")
211
  location_submit = gr.Button("Analyze Location")
212
  location_output = gr.Textbox(label="Analysis Results", lines=15)
213
 
214
- def process_location_tab():
215
- return analyze_environmental_impact(
216
- api_key.value,
217
- "Geographical Assessment",
218
- image=None,
219
- text_input=None,
220
- location=location_input_tab.value,
221
- product_info=None
222
- )
223
-
224
  location_submit.click(
225
- fn=process_location_tab,
226
- inputs=None,
 
 
 
 
 
 
 
227
  outputs=location_output
228
  )
229
 
230
  with gr.TabItem("Product Assessment"):
231
- product_info_tab = gr.Textbox(
232
  label="Product Information",
233
  placeholder="Describe the product, materials, manufacturing process, lifecycle, etc.",
234
  lines=5
@@ -236,24 +224,21 @@ with gr.Blocks(title="Smart Environmental Impact Analyzer") as app:
236
  product_submit = gr.Button("Analyze Product")
237
  product_output = gr.Textbox(label="Analysis Results", lines=15)
238
 
239
- def process_product_tab():
240
- return analyze_environmental_impact(
241
- api_key.value,
242
- "Product Assessment",
243
- image=None,
244
- text_input=None,
245
- location=None,
246
- product_info=product_info_tab.value
247
- )
248
-
249
  product_submit.click(
250
- fn=process_product_tab,
251
- inputs=None,
 
 
 
 
 
 
 
252
  outputs=product_output
253
  )
254
 
255
  with gr.TabItem("Custom Query"):
256
- custom_input_tab = gr.Textbox(
257
  label="Custom Environmental Query",
258
  placeholder="Enter your environmental question or describe a scenario to analyze",
259
  lines=5
@@ -261,19 +246,16 @@ with gr.Blocks(title="Smart Environmental Impact Analyzer") as app:
261
  custom_submit = gr.Button("Analyze")
262
  custom_output = gr.Textbox(label="Analysis Results", lines=15)
263
 
264
- def process_custom_tab():
265
- return analyze_environmental_impact(
266
- api_key.value,
267
- "Custom Query",
268
- image=None,
269
- text_input=custom_input_tab.value,
270
- location=None,
271
- product_info=None
272
- )
273
-
274
  custom_submit.click(
275
- fn=process_custom_tab,
276
- inputs=None,
 
 
 
 
 
 
 
277
  outputs=custom_output
278
  )
279
 
 
178
 
179
  api_key = gr.Textbox(label="OpenRouter API Key", placeholder="Enter your OpenRouter API key", type="password")
180
 
 
 
 
 
 
 
181
  with gr.Tabs():
182
  with gr.TabItem("Image Analysis"):
183
+ image_input = gr.Image(type="pil", label="Upload an image for environmental analysis")
184
  image_submit = gr.Button("Analyze Image")
185
  image_output = gr.Textbox(label="Analysis Results", lines=15)
186
 
 
 
 
 
 
 
 
 
 
 
187
  image_submit.click(
188
+ analyze_environmental_impact,
189
+ inputs=[
190
+ api_key, # Directly pass the api_key component
191
+ gr.Textbox(value="Image Analysis", visible=False),
192
+ image_input,
193
+ gr.Textbox(value="", visible=False),
194
+ gr.Textbox(value="", visible=False),
195
+ gr.Textbox(value="", visible=False)
196
+ ],
197
  outputs=image_output
198
  )
199
 
200
  with gr.TabItem("Geographical Assessment"):
201
+ location_input = gr.Textbox(label="Location (city, region, or country)", placeholder="e.g., Paris, France")
202
  location_submit = gr.Button("Analyze Location")
203
  location_output = gr.Textbox(label="Analysis Results", lines=15)
204
 
 
 
 
 
 
 
 
 
 
 
205
  location_submit.click(
206
+ analyze_environmental_impact,
207
+ inputs=[
208
+ api_key, # Directly pass the api_key component
209
+ gr.Textbox(value="Geographical Assessment", visible=False),
210
+ gr.Image(value=None, visible=False, type="pil"),
211
+ gr.Textbox(value="", visible=False),
212
+ location_input,
213
+ gr.Textbox(value="", visible=False)
214
+ ],
215
  outputs=location_output
216
  )
217
 
218
  with gr.TabItem("Product Assessment"):
219
+ product_info = gr.Textbox(
220
  label="Product Information",
221
  placeholder="Describe the product, materials, manufacturing process, lifecycle, etc.",
222
  lines=5
 
224
  product_submit = gr.Button("Analyze Product")
225
  product_output = gr.Textbox(label="Analysis Results", lines=15)
226
 
 
 
 
 
 
 
 
 
 
 
227
  product_submit.click(
228
+ analyze_environmental_impact,
229
+ inputs=[
230
+ api_key, # Directly pass the api_key component
231
+ gr.Textbox(value="Product Assessment", visible=False),
232
+ gr.Image(value=None, visible=False, type="pil"),
233
+ gr.Textbox(value="", visible=False),
234
+ gr.Textbox(value="", visible=False),
235
+ product_info
236
+ ],
237
  outputs=product_output
238
  )
239
 
240
  with gr.TabItem("Custom Query"):
241
+ custom_input = gr.Textbox(
242
  label="Custom Environmental Query",
243
  placeholder="Enter your environmental question or describe a scenario to analyze",
244
  lines=5
 
246
  custom_submit = gr.Button("Analyze")
247
  custom_output = gr.Textbox(label="Analysis Results", lines=15)
248
 
 
 
 
 
 
 
 
 
 
 
249
  custom_submit.click(
250
+ analyze_environmental_impact,
251
+ inputs=[
252
+ api_key, # Directly pass the api_key component
253
+ gr.Textbox(value="Custom Query", visible=False),
254
+ gr.Image(value=None, visible=False, type="pil"),
255
+ custom_input,
256
+ gr.Textbox(value="", visible=False),
257
+ gr.Textbox(value="", visible=False)
258
+ ],
259
  outputs=custom_output
260
  )
261