Update pages/Report_Writer.py
Browse files- pages/Report_Writer.py +30 -31
pages/Report_Writer.py
CHANGED
|
@@ -9,7 +9,7 @@ from llama_index.embeddings.fastembed import FastEmbedEmbedding
|
|
| 9 |
import google.generativeai as genai
|
| 10 |
import os
|
| 11 |
import PyPDF2
|
| 12 |
-
import streamlit_analytics2 as streamlit_analytics
|
| 13 |
|
| 14 |
|
| 15 |
# Set up Google API key
|
|
@@ -92,40 +92,39 @@ def main():
|
|
| 92 |
st.title("AI Report Writer")
|
| 93 |
st.write("Upload your document and our AI will generate a comprehensive report based on its contents!")
|
| 94 |
|
| 95 |
-
with streamlit_analytics.track():
|
| 96 |
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
# Report format input
|
| 101 |
-
report_format = st.text_area("Enter the desired report format (optional)", height=150,
|
| 102 |
-
help="Leave blank to use a default template")
|
| 103 |
-
|
| 104 |
-
# Additional information input
|
| 105 |
-
additional_info = st.text_area("Enter any additional information or context for the report", height=100)
|
| 106 |
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
| 111 |
-
document_text = ""
|
| 112 |
-
for page in pdf_reader.pages:
|
| 113 |
-
document_text += page.extract_text()
|
| 114 |
-
else:
|
| 115 |
-
document_text = uploaded_file.getvalue().decode("utf-8")
|
| 116 |
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
else:
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
|
| 130 |
if __name__ == "__main__":
|
| 131 |
main()
|
|
|
|
| 9 |
import google.generativeai as genai
|
| 10 |
import os
|
| 11 |
import PyPDF2
|
| 12 |
+
#import streamlit_analytics2 as streamlit_analytics
|
| 13 |
|
| 14 |
|
| 15 |
# Set up Google API key
|
|
|
|
| 92 |
st.title("AI Report Writer")
|
| 93 |
st.write("Upload your document and our AI will generate a comprehensive report based on its contents!")
|
| 94 |
|
|
|
|
| 95 |
|
| 96 |
+
# File uploader
|
| 97 |
+
uploaded_file = st.file_uploader("Choose a file (PDF or TXT)", type=["txt", "pdf"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
+
# Report format input
|
| 100 |
+
report_format = st.text_area("Enter the desired report format (optional)", height=150,
|
| 101 |
+
help="Leave blank to use a default template")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
+
# Additional information input
|
| 104 |
+
additional_info = st.text_area("Enter any additional information or context for the report", height=100)
|
| 105 |
+
|
| 106 |
+
if uploaded_file is not None:
|
| 107 |
+
# Read file contents
|
| 108 |
+
if uploaded_file.type == "application/pdf":
|
| 109 |
+
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
| 110 |
+
document_text = ""
|
| 111 |
+
for page in pdf_reader.pages:
|
| 112 |
+
document_text += page.extract_text()
|
| 113 |
else:
|
| 114 |
+
document_text = uploaded_file.getvalue().decode("utf-8")
|
| 115 |
+
|
| 116 |
+
if st.button("Generate Report"):
|
| 117 |
+
st.write("Analyzing document and generating report...")
|
| 118 |
+
|
| 119 |
+
# Load data and generate report
|
| 120 |
+
doc_list = document_text.split(".")
|
| 121 |
+
index = load_data(document_text)
|
| 122 |
+
report = generate_report(index, report_format, additional_info)
|
| 123 |
+
|
| 124 |
+
st.write("## Generated Report")
|
| 125 |
+
st.write(report)
|
| 126 |
+
else:
|
| 127 |
+
st.warning("Please upload a file to generate a report.")
|
| 128 |
|
| 129 |
if __name__ == "__main__":
|
| 130 |
main()
|