CoderHassan commited on
Commit
e19cdf1
Β·
verified Β·
1 Parent(s): b792d88

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -3,6 +3,10 @@ import requests
3
  import streamlit as st
4
  import pandas as pd
5
  from scraper import scrape_tariffs
 
 
 
 
6
 
7
  # Streamlit App: ⚑ EnergyGuru_PowerCalc: AI-Driven Bill & Carbon Footprint Tracker
8
  st.title("⚑ EnergyGuru_PowerCalc: AI-Driven Bill & Carbon Footprint Tracker")
@@ -113,6 +117,26 @@ 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.")
118
 
 
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: ⚑ EnergyGuru_PowerCalc: AI-Driven Bill & Carbon Footprint Tracker
12
  st.title("⚑ EnergyGuru_PowerCalc: AI-Driven Bill & Carbon Footprint Tracker")
 
117
  st.subheader("πŸ’΅ Electricity Bill & 🌍 Carbon Footprint")
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 to calculate the electricity bill and carbon footprint.")
142