OGrohit commited on
Commit
0c09d7b
·
verified ·
1 Parent(s): 6f4a2ba

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -31
app.py CHANGED
@@ -1,4 +1,6 @@
1
  import streamlit as st
 
 
2
 
3
  st.set_page_config(page_title="Smart Waste Segregation Advisor")
4
 
@@ -10,8 +12,11 @@ This tool helps users identify waste categories and provides guidance
10
  for responsible disposal using AI-based reasoning.
11
  """)
12
 
13
- # Image upload (UI purpose)
14
- uploaded_image = st.file_uploader("Upload an image of the waste item (optional)", type=["jpg", "png", "jpeg"])
 
 
 
15
 
16
  # Optional text input
17
  user_text = st.text_input("Optional: Describe the waste item")
@@ -19,47 +24,38 @@ user_text = st.text_input("Optional: Describe the waste item")
19
  st.divider()
20
 
21
  if st.button("Analyze Waste"):
22
- # Simulated image interpretation
23
  if uploaded_image:
24
  image_description = "An image showing a waste item uploaded by the user"
25
  else:
26
  image_description = "No image provided"
27
 
 
 
 
 
 
 
28
  prompt = f"""
29
  You are an AI-powered Smart Waste Segregation Advisor.
30
 
31
- You will receive:
32
- 1. A brief description of an uploaded image (assume the image shows a waste item)
33
- 2. Optional text input from the user
34
-
35
- Your tasks:
36
- 1. Identify the waste item based on the input.
37
- 2. Classify the item into one of the following categories:
38
- - Wet Waste
39
- - Dry Waste
40
- - E-Waste
41
- 3. Explain briefly why the item belongs to this category.
42
- 4. Suggest the correct and safe disposal method.
43
- 5. Explain the environmental impact if the item is disposed of incorrectly.
44
 
45
  User Input:
46
  Image description: {image_description}
47
- Additional text: {user_text}
48
  """
49
 
50
- # Simulated AI response (semi-working prototype)
51
- response = """
52
- **Waste Category:** Dry Waste
53
-
54
- **Reason:**
55
- Plastic-based items are non-biodegradable and commonly recyclable.
56
-
57
- **Disposal Method:**
58
- Dispose of the item in a dry waste or recycling bin.
59
-
60
- **Environmental Impact:**
61
- Improper disposal can cause long-term pollution and harm wildlife.
62
- """
63
 
64
  st.markdown("### 🧠 AI Analysis Result")
65
- st.markdown(response)
 
1
  import streamlit as st
2
+ from huggingface_hub import InferenceClient
3
+ import os
4
 
5
  st.set_page_config(page_title="Smart Waste Segregation Advisor")
6
 
 
12
  for responsible disposal using AI-based reasoning.
13
  """)
14
 
15
+ # Image upload
16
+ uploaded_image = st.file_uploader(
17
+ "Upload an image of the waste item (optional)",
18
+ type=["jpg", "png", "jpeg"]
19
+ )
20
 
21
  # Optional text input
22
  user_text = st.text_input("Optional: Describe the waste item")
 
24
  st.divider()
25
 
26
  if st.button("Analyze Waste"):
 
27
  if uploaded_image:
28
  image_description = "An image showing a waste item uploaded by the user"
29
  else:
30
  image_description = "No image provided"
31
 
32
+ # 🔐 Initialize IBM Granite via HF Inference API
33
+ client = InferenceClient(
34
+ model="ibm-granite/granite-3.0-2b-instruct",
35
+ token=os.getenv("HF_TOKEN")
36
+ )
37
+
38
  prompt = f"""
39
  You are an AI-powered Smart Waste Segregation Advisor.
40
 
41
+ Tasks:
42
+ 1. Identify the waste item.
43
+ 2. Classify it as Wet Waste, Dry Waste, or E-Waste.
44
+ 3. Explain the reason.
45
+ 4. Suggest correct disposal.
46
+ 5. Explain environmental impact.
 
 
 
 
 
 
 
47
 
48
  User Input:
49
  Image description: {image_description}
50
+ User text: {user_text}
51
  """
52
 
53
+ with st.spinner("Analyzing using IBM Granite AI..."):
54
+ response = client.text_generation(
55
+ prompt,
56
+ max_new_tokens=250,
57
+ temperature=0.7
58
+ )
 
 
 
 
 
 
 
59
 
60
  st.markdown("### 🧠 AI Analysis Result")
61
+ st.write(response)