Spaces:
Build error
Build error
Update app.py
Browse files
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.")
|