IAMTFRMZA commited on
Commit
b320475
·
verified ·
1 Parent(s): bc11e7d
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -15,6 +15,7 @@ st.caption("Chat with an AI Assistant on your LOR Chat Report")
15
  with st.sidebar:
16
  OPENAI_API_KEY = st.text_input("Enter your C2 Group of Technologies Access Key", type="password")
17
 
 
18
  if OPENAI_API_KEY:
19
  client = OpenAI(api_key=OPENAI_API_KEY)
20
  else:
@@ -47,7 +48,7 @@ if uploaded_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
 
@@ -91,17 +92,21 @@ if uploaded_file:
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)}")
 
15
  with st.sidebar:
16
  OPENAI_API_KEY = st.text_input("Enter your C2 Group of Technologies Access Key", type="password")
17
 
18
+ # Check for valid API key
19
  if OPENAI_API_KEY:
20
  client = OpenAI(api_key=OPENAI_API_KEY)
21
  else:
 
48
  st.write(df)
49
 
50
  # Process user input
51
+ prompt = f"Please analyze the following data: {df.head()}"
52
  st.session_state.messages.append({"role": "user", "content": prompt})
53
  st.chat_message("user").write(prompt)
54
 
 
92
  doc.add_heading('AI Assistant Report', 0)
93
  doc.add_paragraph(assistant_message)
94
 
95
+ # Define the save path - Ensure it's accessible
96
+ try:
97
+ word_filename = "/mnt/data/AI_Report.docx"
98
+ doc.save(word_filename)
99
+
100
+ # Provide download link
101
+ with open(word_filename, "rb") as file:
102
+ st.download_button(
103
+ label="Download the Report",
104
+ data=file.read(),
105
+ file_name="AI_Report.docx",
106
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
107
+ )
108
+ except Exception as e:
109
+ st.error(f"Error saving the document: {str(e)}")
110
 
 
 
 
 
 
 
 
 
111
  except Exception as e:
112
+ st.error(f"Error processing the chat: {str(e)}")