Engineer786 commited on
Commit
95bffc2
Β·
verified Β·
1 Parent(s): a19d394

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -9
app.py CHANGED
@@ -3,7 +3,10 @@ import requests
3
  import streamlit as st
4
  import pandas as pd
5
  from scraper import scrape_tariffs
6
- from groq import Groq # Import Groq API
 
 
 
7
 
8
  # Streamlit App: Electricity Bill & Carbon Footprint Estimator
9
  st.title("πŸ”Œ Electricity Bill & Carbon Footprint Estimator")
@@ -35,9 +38,6 @@ appliances = {
35
  "Water Heater (2000W)": 2000,
36
  }
37
 
38
- # Groq client setup for advice generation
39
- client = Groq(api_key=os.environ.get('GroqApi'))
40
-
41
  def scrape_data():
42
  """
43
  Scrapes tariff data from the provided URLs.
@@ -118,18 +118,24 @@ if st.session_state["appliance_list"] and rate_per_kwh > 0:
118
  st.write(f"πŸ’΅ **Estimated Electricity Bill**: **{bill_amount:.2f} PKR**")
119
  st.write(f"🌍 **Estimated Carbon Footprint**: **{carbon_footprint:.2f} kg CO2 per month**")
120
 
121
- # Get advice to reduce carbon footprint using Groq API
 
 
 
122
  chat_completion = client.chat.completions.create(
123
  messages=[{
124
  "role": "user",
125
- "content": f"Provide a few tips (3 or 4) on how to reduce the carbon footprint caused by electricity usage of {carbon_footprint:.2f} kg CO2 per month."
 
 
 
 
126
  }],
127
- model="llama3-8b-8192", # Specify the model
128
  )
129
 
130
  advice = chat_completion.choices[0].message.content
131
  st.subheader("πŸ’‘ Tips to Reduce Carbon Footprint")
132
  st.write(advice)
133
-
134
  else:
135
- st.info("ℹ️ Add appliances to calculate the electricity bill and carbon footprint.")
 
3
  import streamlit as st
4
  import pandas as pd
5
  from scraper import scrape_tariffs
6
+ from groq import Groq
7
+
8
+ # Initialize Groq client
9
+ client = Groq(api_key=os.environ.get('GroqApi'))
10
 
11
  # Streamlit App: Electricity Bill & Carbon Footprint Estimator
12
  st.title("πŸ”Œ Electricity Bill & Carbon Footprint Estimator")
 
38
  "Water Heater (2000W)": 2000,
39
  }
40
 
 
 
 
41
  def scrape_data():
42
  """
43
  Scrapes tariff data from the provided URLs.
 
118
  st.write(f"πŸ’΅ **Estimated Electricity Bill**: **{bill_amount:.2f} PKR**")
119
  st.write(f"🌍 **Estimated Carbon Footprint**: **{carbon_footprint:.2f} kg CO2 per month**")
120
 
121
+ # Generate Groq-based advice to reduce carbon footprint
122
+ appliance_names = [appliance["appliance"] for appliance in st.session_state["appliance_list"]]
123
+ appliance_list_str = ", ".join(appliance_names)
124
+
125
  chat_completion = client.chat.completions.create(
126
  messages=[{
127
  "role": "user",
128
+ "content": (
129
+ f"Provide exactly 3 to 4 short, one-line tips to reduce the carbon footprint caused "
130
+ f"by the usage of the following appliances: {appliance_list_str}. The tips should be "
131
+ f"practical and relevant to these appliances only."
132
+ )
133
  }],
134
+ model="llama3-8b-8192",
135
  )
136
 
137
  advice = chat_completion.choices[0].message.content
138
  st.subheader("πŸ’‘ Tips to Reduce Carbon Footprint")
139
  st.write(advice)
 
140
  else:
141
+ st.info("ℹ️ Add appliances and ensure a valid tariff rate is selected to calculate the electricity bill and carbon footprint.")