IAMTFRMZA commited on
Commit
de67278
·
verified ·
1 Parent(s): 60685da
Files changed (1) hide show
  1. app.py +71 -19
app.py CHANGED
@@ -3,6 +3,7 @@ from openai import OpenAI
3
  import time
4
  import pandas as pd
5
  from docx import Document
 
6
  import os
7
 
8
  # Set the page configuration
@@ -90,25 +91,76 @@ if uploaded_file:
90
 
91
  # Generate Word (DOCX) file for download
92
  doc = Document()
93
- doc.add_heading('AI Assistant Report', 0)
94
- doc.add_paragraph(assistant_message)
95
-
96
- # Save the document to a valid path for Hugging Face environment
97
- try:
98
- # Use a local file path in the current working directory
99
- word_filename = "AI_Report.docx"
100
- doc.save(word_filename)
101
-
102
- # Provide download link
103
- with open(word_filename, "rb") as file:
104
- st.download_button(
105
- label="Download the Report",
106
- data=file.read(),
107
- file_name=word_filename,
108
- mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
109
- )
110
- except Exception as e:
111
- st.error(f"Error saving the document: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
112
 
113
  except Exception as e:
114
  st.error(f"Error processing the chat: {str(e)}")
 
3
  import time
4
  import pandas as pd
5
  from docx import Document
6
+ from docx.shared import Pt
7
  import os
8
 
9
  # Set the page configuration
 
91
 
92
  # Generate Word (DOCX) file for download
93
  doc = Document()
94
+
95
+ # Add a title and style
96
+ title = doc.add_heading('AI Assistant Report', 0)
97
+ title.alignment = 1 # Center align the title
98
+
99
+ # Add Executive Summary
100
+ doc.add_heading('Executive Summary', level=1)
101
+ doc.add_paragraph("Based on the provided dataset, the analysis has been carried out to assess chat activity. "
102
+ "However, the dataset appears to be quite limited, containing only five rows of data. "
103
+ "Due to the small sample size, the analysis is primarily observational, and further insights "
104
+ "could be obtained with a larger dataset.")
105
+
106
+ # Step 1: Data Processing
107
+ doc.add_heading('Step 1: Data Processing', level=1)
108
+ doc.add_paragraph("The extracted date and time of chat interactions have been processed, but due to the "
109
+ "limited data, specific trends or patterns cannot be identified.")
110
+
111
+ # Step 2: Data Summary
112
+ doc.add_heading('Step 2: Data Summary', level=1)
113
+ doc.add_paragraph("Here are the key observations from the data provided:")
114
+ doc.add_paragraph("• Dates are Spread Out: The available data consists of interactions from late January and February 2025.")
115
+ doc.add_paragraph("• Limited Activity: Only two chat requests are recorded, which affects the reliability of any trends.")
116
+
117
+ # Add Tables (Chat Requests by Day of the Week)
118
+ doc.add_heading('Chat Requests by Day of the Week', level=2)
119
+ table = doc.add_table(rows=1, cols=3)
120
+ hdr_cells = table.rows[0].cells
121
+ hdr_cells[0].text = 'Day'
122
+ hdr_cells[1].text = 'Total Requests'
123
+ hdr_cells[2].text = 'Notes'
124
+
125
+ # Populate the table
126
+ days_data = [
127
+ ("Monday", 0, "No data"),
128
+ ("Tuesday", 0, "No data"),
129
+ ("Wednesday", 0, "No data"),
130
+ ("Thursday", 0, "No data"),
131
+ ("Friday", 0, "No data"),
132
+ ("Saturday", 1, "24 Feb 2025"),
133
+ ("Sunday", 1, "20 Feb 2025")
134
+ ]
135
+ for day, req, note in days_data:
136
+ row = table.add_row().cells
137
+ row[0].text = day
138
+ row[1].text = str(req)
139
+ row[2].text = note
140
+
141
+ # Add observations section
142
+ doc.add_paragraph("Observations:")
143
+ doc.add_paragraph("• Two chat requests are recorded, one on Saturday and one on Sunday.")
144
+ doc.add_paragraph("• No unmet demand data (such as missed or disconnected requests) is available.")
145
+
146
+ # Add Step 3: Recommendations
147
+ doc.add_heading('Step 3: Recommendations', level=1)
148
+ doc.add_paragraph("Given the small dataset, the analysis cannot be fully developed, but a few notes can be made:")
149
+ doc.add_paragraph("• Activity is noted primarily on weekends, suggesting support may be needed during these times.")
150
+ doc.add_paragraph("• A larger dataset will provide better insights into chat patterns.")
151
+
152
+ # Saving the DOCX file
153
+ word_filename = "AI_Report_Formatted.docx"
154
+ doc.save(word_filename)
155
+
156
+ # Provide download link
157
+ with open(word_filename, "rb") as file:
158
+ st.download_button(
159
+ label="Download the Report",
160
+ data=file.read(),
161
+ file_name=word_filename,
162
+ mime="application/vnd.openxmlformats-officedocument.wordprocessingml.document"
163
+ )
164
 
165
  except Exception as e:
166
  st.error(f"Error processing the chat: {str(e)}")