Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 10 |
-
|
| 11 |
-
image.save(image_path)
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 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 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
)
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|