Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import plotly.express as px
|
| 4 |
+
|
| 5 |
+
from pdf_parser import extract_text
|
| 6 |
+
from esg_metrics import extract_scope, extract_revenue, carbon_intensity
|
| 7 |
+
from vector_store import index_doc
|
| 8 |
+
from hyperrag import build_graph
|
| 9 |
+
from analysis import answer
|
| 10 |
+
from discourse_graph import add_claim, detect_greenwashing
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
st.set_page_config(
|
| 14 |
+
page_title="ESG HyperRAG Platform",
|
| 15 |
+
layout="wide"
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
st.title("🌍 ESG HyperRAG Intelligence Platform")
|
| 19 |
+
|
| 20 |
+
st.sidebar.header("Upload ESG Report")
|
| 21 |
+
|
| 22 |
+
file = st.sidebar.file_uploader("Upload ESG PDF", type=["pdf"])
|
| 23 |
+
|
| 24 |
+
company = st.sidebar.text_input("Company")
|
| 25 |
+
|
| 26 |
+
sector = st.sidebar.text_input("Sector")
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
if st.sidebar.button("Analyze Report"):
|
| 30 |
+
|
| 31 |
+
if file and company and sector:
|
| 32 |
+
|
| 33 |
+
text = extract_text(file)
|
| 34 |
+
|
| 35 |
+
scope1 = extract_scope(text,1)
|
| 36 |
+
|
| 37 |
+
scope2 = extract_scope(text,2)
|
| 38 |
+
|
| 39 |
+
scope3 = extract_scope(text,3)
|
| 40 |
+
|
| 41 |
+
revenue = extract_revenue(text)
|
| 42 |
+
|
| 43 |
+
intensity = carbon_intensity(scope1, revenue)
|
| 44 |
+
|
| 45 |
+
index_doc(text,{
|
| 46 |
+
"company":company,
|
| 47 |
+
"sector":sector,
|
| 48 |
+
"scope1":scope1,
|
| 49 |
+
"scope2":scope2,
|
| 50 |
+
"scope3":scope3,
|
| 51 |
+
"revenue":revenue,
|
| 52 |
+
"carbon_intensity":intensity
|
| 53 |
+
})
|
| 54 |
+
|
| 55 |
+
build_graph([text])
|
| 56 |
+
|
| 57 |
+
add_claim(company,"low emissions",f"Scope1 {scope1}")
|
| 58 |
+
|
| 59 |
+
st.success("Report processed successfully")
|
| 60 |
+
|
| 61 |
+
df = pd.DataFrame({
|
| 62 |
+
|
| 63 |
+
"Scope":["Scope1","Scope2","Scope3"],
|
| 64 |
+
|
| 65 |
+
"Value":[scope1,scope2,scope3]
|
| 66 |
+
|
| 67 |
+
})
|
| 68 |
+
|
| 69 |
+
fig = px.bar(
|
| 70 |
+
|
| 71 |
+
df,
|
| 72 |
+
|
| 73 |
+
x="Scope",
|
| 74 |
+
|
| 75 |
+
y="Value",
|
| 76 |
+
|
| 77 |
+
color="Scope",
|
| 78 |
+
|
| 79 |
+
title="Emission Breakdown"
|
| 80 |
+
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
st.plotly_chart(fig,use_container_width=True)
|
| 84 |
+
|
| 85 |
+
st.metric("Carbon Intensity", intensity)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
st.header("🔎 HyperRAG ESG Query")
|
| 89 |
+
|
| 90 |
+
query = st.text_input("Ask ESG question")
|
| 91 |
+
|
| 92 |
+
if st.button("Run Query"):
|
| 93 |
+
|
| 94 |
+
result = answer(query)
|
| 95 |
+
|
| 96 |
+
st.text(result)
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
st.header("🚨 Greenwashing Detection")
|
| 100 |
+
|
| 101 |
+
if st.button("Check Greenwashing"):
|
| 102 |
+
|
| 103 |
+
issues = detect_greenwashing()
|
| 104 |
+
|
| 105 |
+
if issues:
|
| 106 |
+
|
| 107 |
+
st.error(f"Potential contradictions detected: {issues}")
|
| 108 |
+
|
| 109 |
+
else:
|
| 110 |
+
|
| 111 |
+
st.success("No contradictions detected")
|