Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 0 additions & 26 deletions README.md

This file was deleted.

28 changes: 28 additions & 0 deletions greenloner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Gen-Ai-Rush-Buildathon

#### Team Name - Greenloner
#### Problem Statement - Enterprises face challenges in creating timely and accurate GHG emission reports according to the latest metrics and directives. The current manual procedure takes one to two quarters, which impedes compliance and sustainability initiatives. To automate report generation, cater to enterprises of various sizes, and ensure fast observance of environmental regulations, a solution is required.
#### Team Leader Email - [email protected]

## A Brief of the Prototype:
<img src="uml-diagram.png">

- Automate the process of creation of GHG emissions using the existing template the firm
uses
- Train a custom LLM with every new iteration of directives and metrics
- Basis the input from the organisation, we would generate the GHG emission report for the
organisation
- Basis the predetermined threshold, we would generate suggestions and roadmaps for the
organisation to reduce their emissions going into the next year
- Generate the list of relevant offset projects to invest in or approximate the amount of credits to buy

## Tech Stack:
- Python
- OpenAI
- LlamaIndex

## Step-by-Step Code Execution Instructions:
The prototype is not complete as the exceeded run time has exhausted OpenAI credits

## What I Learned:
Pivoting to an idea that adds business value is more important than building complex technical systems.
81 changes: 81 additions & 0 deletions greenloner/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import streamlit as st

def calculate_and_display_score(people_in_household,electric_input, gas_input, oil_input, car_input, flights_4_less_input, flights_4_more_input, recycle_newspaper_selection, recycle_alum_tin_selection):
# Function to calculate and display the carbon footprint score

def is_checked(option, selected_option):
return option == selected_option

# Check selection made for recycling newspaper before calculating and displaying score
if (not is_checked(recycle_newspaper_selection, "Yes") and not is_checked(recycle_newspaper_selection, "No")) or \
(not is_checked(recycle_alum_tin_selection, "Yes") and not is_checked(recycle_alum_tin_selection, "No")):
st.error("Please select whether you recycle newspapers and aluminum/tin.")
else:
# Convert radio button selections to boolean values
recycle_newspaper_selection_yes = is_checked(recycle_newspaper_selection, "Yes")
recycle_alum_tin_selection_yes = is_checked(recycle_alum_tin_selection, "Yes")

# Set variables for calculating each component score
newspaper_score = 0 if recycle_newspaper_selection_yes else 184
alum_tin_score = 0 if recycle_alum_tin_selection_yes else 166

electric_score = 0 if electric_input == 0 or electric_input == "undefined" else electric_input * 105
gas_score = 0 if gas_input == 0 or gas_input == "undefined" else gas_input * 105
oil_score = 0 if oil_input == 0 or oil_input == "undefined" else oil_input * 113
car_score = 0 if car_input == 0 or car_input == "undefined" else car_input * 0.79
flights_4_less_score = 0 if flights_4_less_input == 0 or flights_4_less_input == "undefined" else flights_4_less_input * 1100
flights_4_more_score = 0 if flights_4_more_input == 0 or flights_4_more_input == "undefined" else flights_4_more_input * 4400

# Calculate scores for each category
energy_score = electric_score + gas_score + oil_score
travel_score = car_score + flights_4_less_score + flights_4_more_score
waste_score = newspaper_score + alum_tin_score

# Calculate total score and round to the nearest whole integer
total_score = round(energy_score + travel_score + waste_score)
formatted_score = "{:,}".format(total_score/people_in_household)

# Display results
st.markdown(f"## Your Carbon Footprint Score: {formatted_score}")


# Main function for the Streamlit app
def main():
# Hide results template and error alerts on initial page load
st.markdown("# Carbon Footprint Calculator")
st.markdown("### Enter the following data to calculate your carbon footprint:")

# Get input values using Streamlit widgets
people_in_household = st.number.input("Number of people in household", value = 0)
electric_input = st.number_input("Electricity consumption (kWh)", value=0.0)
gas_input = st.number_input("Gas consumption (therms)", value=0.0)
oil_input = st.number_input("Oil consumption (gallons)", value=0.0)
car_input = st.number_input("Car travel (miles)", value=0.0)
flights_4_less_input = st.number_input("Flights taken 4 hours or less", value=0.0)
flights_4_more_input = st.number_input("Flights taken 4 hours or more", value=0.0)

recycle_newspaper_selection = st.radio("Do you recycle newspapers?", ("Yes", "No"))
recycle_alum_tin_selection = st.radio("Do you recycle aluminum and tin?", ("Yes", "No"))

# Add click event listener for the Calculate button
if st.button("Calculate"):
# Convert radio button selections to boolean values
recycle_newspaper_selection_yes = recycle_newspaper_selection == "Yes"
recycle_newspaper_selection_no = recycle_newspaper_selection == "No"
recycle_alum_tin_selection_yes = recycle_alum_tin_selection == "Yes"
recycle_alum_tin_selection_no = recycle_alum_tin_selection == "No"

# Check selection made for recycling newspaper before calculating and displaying score
if (not recycle_newspaper_selection_yes and not recycle_newspaper_selection_no) or \
(not recycle_alum_tin_selection_yes and not recycle_alum_tin_selection_no):
if not recycle_newspaper_selection_yes and not recycle_newspaper_selection_no:
st.error("Please select whether you recycle newspapers.")
if not recycle_alum_tin_selection_yes and not recycle_alum_tin_selection_no:
st.error("Please select whether you recycle aluminum and tin.")
else:
# Calculate and display the carbon footprint score
calculate_and_display_score(people_in_household,electric_input, gas_input, oil_input, car_input, flights_4_less_input, flights_4_more_input, recycle_newspaper_selection, recycle_alum_tin_selection)

# Entry point of the Streamlit app
if __name__ == "__main__":
main()
77 changes: 77 additions & 0 deletions greenloner/app1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import streamlit as st
import urllib
import base64
import os
from llama_index import VectorStoreIndex, SimpleDirectoryReader, ListIndex
from dotenv import load_dotenv

#load_dotenv()

import openai
os.environ['OPENAI_API_KEY'] = ""

def create_data_directory():
if not os.path.exists("data"):
os.makedirs("data")

#function to save a file
def save_uploadedfile(uploadedfile):
with open(os.path.join("data",uploadedfile.name),"wb") as f:
f.write(uploadedfile.getbuffer())
return st.success("Saved File:{} to directory".format(uploadedfile.name))

@st.cache_data
#function to display the PDF of a given file
def displayPDF(file):
# Opening file from file path
with open(file, "rb") as f:
base64_pdf = base64.b64encode(f.read()).decode('utf-8')

# Embedding PDF in HTML
pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'

# Displaying File
st.markdown(pdf_display, unsafe_allow_html=True)

#semantic search
def semantic_search(query):
documents = SimpleDirectoryReader('data').load_data()
index = ListIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query(query)
return response
#summarization
def summarize(file):
documents = SimpleDirectoryReader('data').load_data()
index = ListIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("Is the report compliant with all the GHG emission metrics?")
return response

#streamlit application
st. set_page_config(layout='wide')

st.title('Semantic Search Application')

uploaded_pdf = st.file_uploader("Upload your PDF", type=['pdf'])

if uploaded_pdf is not None:
col1,col2,col3 = st.columns([2,1,1])
with col1:
input_file = save_uploadedfile(uploaded_pdf)
pdf_file = "data/"+uploaded_pdf.name
pdf_view = displayPDF(pdf_file)
with col2:
st.success("Search Area")
query_search = st.text_area("Search your query")
if st.checkbox("search"):
st.info("Your query: "+query_search)
result = semantic_search(query_search)
st.write(result.response)
print(result)
with col3:
st.success("Automated Summarization")
summary_result = summarize(pdf_file)
st.write(summary_result.response)
print(summary_result)

79 changes: 79 additions & 0 deletions greenloner/app2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import streamlit as st
import urllib
import base64
import os
from llama_index import VectorStoreIndex, SimpleDirectoryReader, GPTListIndex
from dotenv import load_dotenv
import openai

load_dotenv()

#os.environ['OPENAI_API_KEY'] =
openai.api_key = ""

#function to save a file
def save_uploadedfile(uploadedfile):
with open(os.path.join("data",uploadedfile.name),"wb") as f:
f.write(uploadedfile.getbuffer())
return st.success("Saved File:{} to directory".format(uploadedfile.name))

@st.cache_data
#function to display the PDF of a given file
def displayPDF(file):
# Opening file from file path
with open(file, "rb") as f:
base64_pdf = base64.b64encode(f.read()).decode('utf-8')

# Embedding PDF in HTML
pdf_display = F'<iframe src="data:application/pdf;base64,{base64_pdf}" width="700" height="1000" type="application/pdf"></iframe>'

# Displaying File
st.markdown(pdf_display, unsafe_allow_html=True)

#semantic search
def semantic_search(query):
print(query)
documents = SimpleDirectoryReader('data').load_data()
#print(documents)
index = VectorStoreIndex.from_documents(documents)
print("testing")
query_engine = index.as_query_engine()
response = query_engine.query(query)
print(response)
return response

#summarization
def summarize(file):
documents = SimpleDirectoryReader('data').load_data()
index = GPTListIndex.from_documents(documents)
#query_engine = index.as_query_engine()
response = index.query(file,response_mode="tree_summarize")
return response

#streamlit application
st. set_page_config(layout='wide')

st.title('Carbon Policy Summarizer')

uploaded_pdf = st.file_uploader("Upload your PDF", type=['pdf'])

if uploaded_pdf is not None:
col1, col2, col3 = st.columns([2,1,1])
with col1:
input_file = save_uploadedfile(uploaded_pdf)
pdf_file = "data/"+uploaded_pdf.name
pdf_view = displayPDF(pdf_file)
with col2:
st.success("Search Area")
query_search = st.text_area("Search your query")
if st.checkbox("search"):
st.info("Your query: "+query_search)
result = semantic_search(query_search)
st.write(result)
with col3:
st.success("Summarization Area")
query_search1 = st.text_area("How do you want to summarize")
if st.checkbox("summarize"):
st.info("Your Summarize prompt: "+query_search1)
summary_result = summarize(query_search1)
st.write(summary_result)
Binary file added greenloner/data/ghg-protocol-revised.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added greenloner/files/FINAL-2017-TCFD-Report.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added greenloner/uml-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.