-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHome.py
More file actions
83 lines (66 loc) · 3.15 KB
/
Home.py
File metadata and controls
83 lines (66 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import streamlit as st
# from PIL import Image
st.set_page_config(page_title="ESG Report Generation",
layout="centered")
st.title("ESG Report Generation")
# Donot show warnings
st.set_option('deprecation.showPyplotGlobalUse', False)
# Sidebar Configuration
st.sidebar.header("Search Parameters")
orgString = st.sidebar.text_input("Organisation", placeholder="Example & Sons")
startDate = st.sidebar.date_input(
"Start Year", help="The starting year for the report data")
endDate = st.sidebar.date_input(
"End Year", help="The closing year for the report data")
PSID = st.sidebar.text_input("Secure1_PSID Cookie", type="password")
PSIDTS = st.sidebar.text_input("Secure1_PSIDTS Cookie", type="password")
generate_doc = st.sidebar.button(label="Generate Document")
# download_doc = st.sidebar.button(label = "Download Generated Document")
refresh_cookie_btn = st.sidebar.button(
label="Refresh Cookies", help="If you run into errors, try refreshing Bard and copy-paste the new cookies here")
upload_image = st.sidebar.file_uploader(
label="Upload Image", type=["png", "jpg"], accept_multiple_files=False)
# Variables
queryString = "Write an ESG report for the company {} based on data from {} to {}"
# if orgString and startDate and endDate and PSID and PSIDTS:
# queryString.format(orgString, startDate.year, endDate.year)
# Query Output
st.header("Search Query")
st.subheader("Your search query looks like this:")
st.write(queryString.format(orgString, startDate.year, endDate.year))
# Below Here
if orgString and startDate and endDate and PSID and PSIDTS:
# try:
from LLMUtils import BardAPIConsumer
llm = BardAPIConsumer(PSID=PSID, PSIDTS=PSIDTS)
st.write(llm.get_report_text(queryString.format(
orgString, startDate.year, endDate.year)))
# Function to read Image Value
if upload_image is not None:
st.write(llm.image_desc(upload_image.getvalue()))
plot_csv = llm.create_plot_html("response.html")
if generate_doc:
byteIO = llm.export_word(llm.get_report_text(
queryString.format(orgString, startDate.year, endDate.year)), plot_csv)
if st.download_button("Download Generated Document", file_name='report.docx', data=byteIO.getvalue()):
# st.download_button()
st.toast("Downloading File!")
if refresh_cookie_btn:
llm.refresh_cookies(PSID=PSID, PSIDTS=PSIDTS)
st.toast("Cookies Refreshed")
# Write for Creating CSv data and Returing plot
# st.caption("below is csv data")
# st.write(llm.create_csv(orgQuery=orgString,
# startYear=startDate.year, endYear=endDate.year))
# st.caption("below is vizualization csv")
# st.pyplot(llm.create_plot_csv("response.csv"))
# llm.create_plot_csv("response.csv")
st.caption("below is html data")
st.write(llm.create_html(orgQuery=orgString,
startYear=startDate.year, endYear=endDate.year))
# st.caption("below is vizualization html")
# st.pyplot(llm.create_plot_html("response.html"))
# except Exception as exp:
# st.warning(exp.args)
# st.warning(
# "Please try refreshing cookies or try later if it doesn't work")