Mujtaba29 commited on
Commit
49b3888
Β·
verified Β·
1 Parent(s): 3ff9818

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -22
app.py CHANGED
@@ -19,20 +19,29 @@ carbon_reduction_data = {
19
  "Tires": 8.0,
20
  }
21
 
22
- # Function to call Groq LLM
23
- def get_recycling_suggestions_from_groq(item, quantity):
24
- prompt = (
25
- f"Suggest profitable and eco-friendly uses for {quantity} kg of {item}, "
26
- f"including household uses, ways to monetize them, and calculate carbon footprint reduction."
27
- )
28
- chat_completion = client.chat.completions.create(
29
- messages=[{"role": "user", "content": prompt}],
30
- model="llama-3.3-70b-versatile",
31
- stream=False,
32
- )
33
- return chat_completion.choices[0].message.content
 
 
 
 
 
 
 
 
 
34
 
35
- # Sidebar with clean navigation and image
36
  st.sidebar.title("🌍 RecycleSmart-PK")
37
  st.sidebar.image(
38
  "https://via.placeholder.com/300x200?text=RecycleSmart+Logo",
@@ -40,8 +49,7 @@ st.sidebar.image(
40
  )
41
  st.sidebar.markdown("### Navigation")
42
  section = st.sidebar.radio(
43
- "Choose a section:",
44
- ["Home", "Recycle Suggestions"]
45
  )
46
 
47
  # Main Content
@@ -54,17 +62,21 @@ if section == "Home":
54
  st.markdown(
55
  """
56
  RecycleSmart-PK helps you turn waste into opportunities while reducing your carbon footprint.
57
- Start by selecting items you want to recycle from the **Recycle Suggestions** tab.
58
  """
59
  )
60
 
61
  elif section == "Recycle Suggestions":
62
  st.title("πŸ’‘ Recycling Suggestions")
63
  selected_items = st.multiselect(
64
- "Select items to recycle:",
65
- list(carbon_reduction_data.keys())
66
  )
67
- quantities = {item: st.number_input(f"Enter quantity for {item} (in kg):", min_value=0, step=1) for item in selected_items}
 
 
 
 
 
68
 
69
  if st.button("Get Suggestions"):
70
  if selected_items:
@@ -72,12 +84,23 @@ elif section == "Recycle Suggestions":
72
  st.write("### ♻️ Suggestions and Impact:")
73
  for item, quantity in quantities.items():
74
  if quantity > 0:
75
- llm_response = get_recycling_suggestions_from_groq(item, quantity)
 
 
 
 
 
 
 
 
 
76
  carbon_reduction = carbon_reduction_data.get(item, 0) * quantity
77
  total_carbon_reduction += carbon_reduction
78
- st.write(f"**πŸ“¦ {item} ({quantity} kg)**")
79
  st.write(f"πŸ’‘ {llm_response}")
80
- st.write(f"🌍 **Carbon Footprint Reduction**: {carbon_reduction:.2f} kg COβ‚‚")
 
 
81
  st.markdown("---")
82
  st.write("### 🌟 Total Carbon Footprint Reduction 🌟")
83
  st.write(f"🌍 **{total_carbon_reduction:.2f} kg COβ‚‚ saved**")
 
19
  "Tires": 8.0,
20
  }
21
 
22
+ # Custom CSS for color and style
23
+ st.markdown(
24
+ """
25
+ <style>
26
+ body {
27
+ background-color: #f0f2f6;
28
+ }
29
+ .main {
30
+ background-color: #ffffff;
31
+ border-radius: 10px;
32
+ padding: 20px;
33
+ color: #333333;
34
+ }
35
+ .sidebar .sidebar-content {
36
+ background-color: #eaf4fc;
37
+ border-radius: 10px;
38
+ }
39
+ </style>
40
+ """,
41
+ unsafe_allow_html=True,
42
+ )
43
 
44
+ # Sidebar with navigation
45
  st.sidebar.title("🌍 RecycleSmart-PK")
46
  st.sidebar.image(
47
  "https://via.placeholder.com/300x200?text=RecycleSmart+Logo",
 
49
  )
50
  st.sidebar.markdown("### Navigation")
51
  section = st.sidebar.radio(
52
+ "Choose a section:", ["Home", "Recycle Suggestions"]
 
53
  )
54
 
55
  # Main Content
 
62
  st.markdown(
63
  """
64
  RecycleSmart-PK helps you turn waste into opportunities while reducing your carbon footprint.
65
+ Navigate to **Recycle Suggestions** to start recycling smartly!
66
  """
67
  )
68
 
69
  elif section == "Recycle Suggestions":
70
  st.title("πŸ’‘ Recycling Suggestions")
71
  selected_items = st.multiselect(
72
+ "Select items to recycle:", list(carbon_reduction_data.keys())
 
73
  )
74
+ quantities = {
75
+ item: st.number_input(
76
+ f"Enter quantity for {item} (in kg):", min_value=0, step=1
77
+ )
78
+ for item in selected_items
79
+ }
80
 
81
  if st.button("Get Suggestions"):
82
  if selected_items:
 
84
  st.write("### ♻️ Suggestions and Impact:")
85
  for item, quantity in quantities.items():
86
  if quantity > 0:
87
+ prompt = (
88
+ f"Suggest profitable and eco-friendly uses for {quantity} kg of {item}, "
89
+ f"including household uses and ways to monetize them."
90
+ )
91
+ chat_completion = client.chat.completions.create(
92
+ messages=[{"role": "user", "content": prompt}],
93
+ model="llama-3.3-70b-versatile",
94
+ stream=False,
95
+ )
96
+ llm_response = chat_completion.choices[0].message.content
97
  carbon_reduction = carbon_reduction_data.get(item, 0) * quantity
98
  total_carbon_reduction += carbon_reduction
99
+ st.write(f"**{item} ({quantity} kg)**")
100
  st.write(f"πŸ’‘ {llm_response}")
101
+ st.write(
102
+ f"🌍 **Carbon Footprint Reduction**: {carbon_reduction:.2f} kg COβ‚‚"
103
+ )
104
  st.markdown("---")
105
  st.write("### 🌟 Total Carbon Footprint Reduction 🌟")
106
  st.write(f"🌍 **{total_carbon_reduction:.2f} kg COβ‚‚ saved**")