OGrohit commited on
Commit
dea363e
Β·
verified Β·
1 Parent(s): 7e36dd7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -38
app.py CHANGED
@@ -1,22 +1,19 @@
1
  import gradio as gr
2
- import os
3
  from classifier import analyze_image
4
 
5
  def analyze(image):
6
  if image is None:
7
  return "Please upload an image."
8
 
9
- # Save image temporarily
10
- image_path = "temp.jpg"
11
- image.save(image_path)
12
 
13
- result = analyze_image(image_path)
 
 
14
 
15
- output = f"""
16
- 🧠 **Detected Object:** {result['detected_object']}
17
- πŸ“Š **Confidence:** {result['confidence']}
18
-
19
- ♻️ **Waste Category:** {result['waste_category']}
20
 
21
  πŸ“ **Reason:**
22
  {result['reason']}
@@ -27,35 +24,23 @@ def analyze(image):
27
  🌍 **Environmental Impact:**
28
  {result['environmental_impact']}
29
  """
30
- return output
31
 
32
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
33
- gr.Markdown(
34
- """
35
- # ♻️ Smart Waste AI
36
- ### AI-powered Waste Segregation Advisor
37
- Upload an image of waste and get instant guidance.
38
- """
39
- )
40
-
41
- with gr.Row():
42
- image_input = gr.Image(type="pil", label="Upload Waste Image")
 
 
 
 
 
 
43
 
44
- analyze_btn = gr.Button("Analyze Waste", variant="primary")
45
- output_box = gr.Markdown()
46
-
47
- analyze_btn.click(
48
- fn=analyze,
49
- inputs=image_input,
50
- outputs=output_box
51
- )
52
-
53
- gr.Markdown(
54
- """
55
- ---
56
- πŸ”— **GitHub Repository:**
57
- https://github.com/rohitdecodes/smart-waste-ai
58
- """
59
- )
60
-
61
  demo.launch()
 
1
  import gradio as gr
 
2
  from classifier import analyze_image
3
 
4
  def analyze(image):
5
  if image is None:
6
  return "Please upload an image."
7
 
8
+ image.save("temp.jpg")
9
+ result = analyze_image("temp.jpg")
 
10
 
11
+ return f"""
12
+ 🧠 **Detected Object:** {result['detected_object']}
13
+ πŸ“Š **Object Confidence:** {result['object_confidence']}
14
 
15
+ ♻️ **Waste Category:** {result['waste_category']}
16
+ πŸ“Š **Waste Confidence:** {result['waste_confidence']}
 
 
 
17
 
18
  πŸ“ **Reason:**
19
  {result['reason']}
 
24
  🌍 **Environmental Impact:**
25
  {result['environmental_impact']}
26
  """
 
27
 
28
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
29
+ gr.Markdown("""
30
+ # ♻️ Smart Waste AI
31
+ **Hybrid AI-powered Waste Segregation Advisor**
32
+ ResNet + CLIP (Zero-shot Vision Reasoning)
33
+ """)
34
+
35
+ image = gr.Image(type="pil", label="Upload Waste Image")
36
+ button = gr.Button("Analyze Waste", variant="primary")
37
+ output = gr.Markdown()
38
+
39
+ button.click(analyze, image, output)
40
+
41
+ gr.Markdown("""
42
+ ---
43
+ πŸ”— **GitHub:** https://github.com/OGrohit/smart-waste-ai
44
+ """)
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  demo.launch()