-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
74 lines (58 loc) · 2.68 KB
/
app.py
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
import streamlit as st
from agents.main import run
from agents.translate import process_file
import pdfkit
class UI:
file_path = r'E:\Trading\Hikmah Wealth Program - V1\Reports\Final Investment Report.md' # Replace with your file path
target_language = 'ta' # Replace with your target language code
translated_file_path = r"E:\Trading\Hikmah Wealth Program - V1\Reports\Translated Final Report.md"
pdf_output_path = r"E:\Trading\Hikmah Wealth Program - V1\Reports\Translated Final Report.pdf"
def __init__(self):
st.set_page_config(page_title="Hikmah Wealth Program", page_icon="📊")
def sidebar(self):
with st.sidebar:
st.header("📊 - Hikmah Wealth Program")
ticker = st.text_input("Enter The Ticker: ", key="ticker", placeholder="Ex. TCS (Tata Consultancy Services)")
if st.button("Generate Report", use_container_width=True):
st.session_state.generating = True
def render(self):
if "ticker" not in st.session_state:
st.session_state.ticker = ""
if "generating" not in st.session_state:
st.session_state.generating = False
if st.session_state.generating:
translated_text = process_file(self.file_path, self.target_language)
try:
with open(self.translated_file_path, "w", encoding='utf-8') as file:
file.write(translated_text)
except Exception as e:
st.error(f"Error writing to file: {str(e)}")
with st.expander("Final Tamil Report"):
st.write(translated_text)
if st.button("Download PDF"):
self.generate_pdf()
def generate_pdf(self):
try:
pdfkit.from_file(self.translated_file_path, self.pdf_output_path)
with open(self.pdf_output_path, "rb") as pdf_file:
pdf_bytes = pdf_file.read()
st.download_button(
label="Click here to download the PDF",
data=pdf_bytes,
file_name="Translated Final Report.pdf",
mime="application/pdf"
)
except Exception as e:
st.error(f"Error generating PDF: {str(e)}")
def run(self):
self.sidebar()
if "generating" not in st.session_state:
st.session_state.generating = False
if st.session_state.generating:
results = run(st.session_state.ticker)
self.render()
st.success("Report Generated Successfully!")
else:
self.render()
if __name__ == "__main__":
UI().run()