File size: 2,291 Bytes
f5153b8
0c09d7b
 
f5153b8
a96d80f
f5153b8
 
 
 
 
 
 
a96d80f
f5153b8
 
a96d80f
0c09d7b
 
 
 
f5153b8
 
 
 
 
a96d80f
f5153b8
a96d80f
 
f5153b8
 
 
 
 
a96d80f
0c09d7b
a96d80f
0c09d7b
 
 
f5153b8
 
 
0c09d7b
 
a96d80f
 
 
 
 
 
 
f5153b8
 
 
0c09d7b
f5153b8
 
0c09d7b
a96d80f
 
 
 
 
 
 
 
 
 
 
 
0c09d7b
 
f5153b8
a96d80f
 
f5153b8
a96d80f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import streamlit as st
from huggingface_hub import InferenceClient
import os

# ---------------- PAGE CONFIG ----------------
st.set_page_config(page_title="Smart Waste Segregation Advisor")

st.title("♻️ AI-Powered Smart Waste Segregation Advisor")
st.subheader("SDG 12: Responsible Consumption and Production")

st.markdown("""
This tool helps users identify waste categories and provides guidance
for responsible disposal using AI-based reasoning powered by IBM Granite.
""")

# ---------------- USER INPUTS ----------------
uploaded_image = st.file_uploader(
    "Upload an image of the waste item (optional)",
    type=["jpg", "png", "jpeg"]
)

user_text = st.text_input("Optional: Describe the waste item")

st.divider()

# ---------------- ANALYZE BUTTON ----------------
if st.button("Analyze Waste"):

    # Simulated image interpretation (Option 1 design choice)
    if uploaded_image:
        image_description = "An image showing a waste item uploaded by the user"
    else:
        image_description = "No image provided"

    # Initialize IBM Granite via Hugging Face Inference API
    client = InferenceClient(
        model="ibm-granite/granite-4.0-mini",
        token=os.getenv("HF_TOKEN")
    )

    prompt = f"""
You are an AI-powered Smart Waste Segregation Advisor.

Tasks:
1. Identify the waste item.
2. Classify it as one of the following:
   - Wet Waste
   - Dry Waste
   - E-Waste
3. Explain briefly why it belongs to this category.
4. Suggest the correct and safe disposal method.
5. Explain the environmental impact if disposed of incorrectly.

User Input:
Image description: {image_description}
User text: {user_text}
"""

    with st.spinner("Analyzing using IBM Granite AI..."):
        response = client.chat_completion(
            messages=[
                {
                    "role": "system",
                    "content": "You are an AI assistant focused on sustainability and responsible waste management."
                },
                {
                    "role": "user",
                    "content": prompt
                }
            ],
            max_tokens=250,
            temperature=0.7
        )

    ai_output = response.choices[0].message["content"]

    st.markdown("### 🧠 AI Analysis Result")
    st.write(ai_output)