Engineer786 commited on
Commit
de9c72b
Β·
verified Β·
1 Parent(s): 4ab941e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -0
app.py CHANGED
@@ -3,6 +3,7 @@ import requests
3
  import streamlit as st
4
  import pandas as pd
5
  from scraper import scrape_tariffs
 
6
 
7
  # Streamlit App: Electricity Bill & Carbon Footprint Estimator
8
  st.title("πŸ”Œ Electricity Bill & Carbon Footprint Estimator")
@@ -34,6 +35,11 @@ appliances = {
34
  "Water Heater (2000W)": 2000,
35
  }
36
 
 
 
 
 
 
37
  def scrape_data():
38
  """
39
  Scrapes tariff data from the provided URLs.
@@ -113,5 +119,19 @@ if st.session_state["appliance_list"] and rate_per_kwh > 0:
113
  st.subheader("πŸ’΅ Electricity Bill & 🌍 Carbon Footprint")
114
  st.write(f"πŸ’΅ **Estimated Electricity Bill**: **{bill_amount:.2f} PKR**")
115
  st.write(f"🌍 **Estimated Carbon Footprint**: **{carbon_footprint:.2f} kg CO2 per month**")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  else:
117
  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 # Import Groq API
7
 
8
  # Streamlit App: Electricity Bill & Carbon Footprint Estimator
9
  st.title("πŸ”Œ Electricity Bill & Carbon Footprint Estimator")
 
35
  "Water Heater (2000W)": 2000,
36
  }
37
 
38
+ # Groq client setup for advice generation
39
+ client = Groq(
40
+ api_key=os.environ.get("GROQ_API_KEY"),
41
+ )
42
+
43
  def scrape_data():
44
  """
45
  Scrapes tariff data from the provided URLs.
 
119
  st.subheader("πŸ’΅ Electricity Bill & 🌍 Carbon Footprint")
120
  st.write(f"πŸ’΅ **Estimated Electricity Bill**: **{bill_amount:.2f} PKR**")
121
  st.write(f"🌍 **Estimated Carbon Footprint**: **{carbon_footprint:.2f} kg CO2 per month**")
122
+
123
+ # Get advice to reduce carbon footprint using Groq API
124
+ chat_completion = client.chat.completions.create(
125
+ messages=[{
126
+ "role": "user",
127
+ "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."
128
+ }],
129
+ model="llama3-8b-8192", # Specify the model
130
+ )
131
+
132
+ advice = chat_completion.choices[0].message.content
133
+ st.subheader("πŸ’‘ Tips to Reduce Carbon Footprint")
134
+ st.write(advice)
135
+
136
  else:
137
  st.info("ℹ️ Add appliances to calculate the electricity bill and carbon footprint.")