Spaces:
Sleeping
Sleeping
app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,15 @@
|
|
1 |
import streamlit as st
|
2 |
from openai import OpenAI
|
3 |
import time
|
|
|
|
|
4 |
|
|
|
5 |
st.set_page_config(page_title="LOR Chat ReportAi")
|
6 |
|
|
|
7 |
st.title("LOR Chat Report Ai Assistant")
|
8 |
-
st.caption("Chat with an
|
9 |
|
10 |
# Sidebar for API Key input
|
11 |
with st.sidebar:
|
@@ -34,7 +38,16 @@ for message in st.session_state.messages:
|
|
34 |
st.chat_message(role).write(content)
|
35 |
|
36 |
# Process user input
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
39 |
st.chat_message("user").write(prompt)
|
40 |
|
@@ -72,6 +85,23 @@ if prompt := st.chat_input():
|
|
72 |
|
73 |
# Store in session state
|
74 |
st.session_state.messages.append({"role": "assistant", "content": assistant_message})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
except Exception as e:
|
77 |
st.error(f"Error: {str(e)}")
|
|
|
1 |
import streamlit as st
|
2 |
from openai import OpenAI
|
3 |
import time
|
4 |
+
import pandas as pd
|
5 |
+
from docx import Document
|
6 |
|
7 |
+
# Set the page configuration
|
8 |
st.set_page_config(page_title="LOR Chat ReportAi")
|
9 |
|
10 |
+
# Title and caption
|
11 |
st.title("LOR Chat Report Ai Assistant")
|
12 |
+
st.caption("Chat with an AI Assistant on your LOR Chat Report")
|
13 |
|
14 |
# Sidebar for API Key input
|
15 |
with st.sidebar:
|
|
|
38 |
st.chat_message(role).write(content)
|
39 |
|
40 |
# Process user input
|
41 |
+
uploaded_file = st.file_uploader("Upload Excel file", type=["xlsx"])
|
42 |
+
|
43 |
+
if uploaded_file:
|
44 |
+
# Read the Excel file
|
45 |
+
df = pd.read_excel(uploaded_file)
|
46 |
+
st.write("Data from uploaded Excel file:")
|
47 |
+
st.write(df)
|
48 |
+
|
49 |
+
# Process user input
|
50 |
+
prompt = f"Please analyze the data in the following format: {df.head()}"
|
51 |
st.session_state.messages.append({"role": "user", "content": prompt})
|
52 |
st.chat_message("user").write(prompt)
|
53 |
|
|
|
85 |
|
86 |
# Store in session state
|
87 |
st.session_state.messages.append({"role": "assistant", "content": assistant_message})
|
88 |
+
|
89 |
+
# Generate Word (DOCX) file for download
|
90 |
+
doc = Document()
|
91 |
+
doc.add_heading('AI Assistant Report', 0)
|
92 |
+
doc.add_paragraph(assistant_message)
|
93 |
+
|
94 |
+
# Save the document
|
95 |
+
word_filename = "/mnt/data/AI_Report.docx"
|
96 |
+
doc.save(word_filename)
|
97 |
+
|
98 |
+
# Provide download link
|
99 |
+
st.download_button(
|
100 |
+
label="Download the Report",
|
101 |
+
data=open(word_filename, "rb").read(),
|
102 |
+
file_name="AI_Report.docx",
|
103 |
+
mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
|
104 |
+
)
|
105 |
|
106 |
except Exception as e:
|
107 |
st.error(f"Error: {str(e)}")
|