IAMTFRMZA commited on
Commit
cfe3a26
·
verified ·
1 Parent(s): 2be630f
Files changed (1) hide show
  1. app.py +53 -7
app.py CHANGED
@@ -4,6 +4,7 @@ import PyPDF2 # Import PyPDF2 for PDF text extraction
4
  from openai import OpenAI
5
  from docx import Document
6
  from docx.shared import Pt
 
7
  import os
8
 
9
  # Set the page configuration
@@ -98,23 +99,67 @@ if uploaded_file:
98
 
99
  # Generate Word (DOCX) file for download
100
  doc = Document()
101
-
102
  # Add a title and style
103
  title = doc.add_heading('AI Assistant Report', 0)
104
- title.alignment = 1 # Center align the title
105
-
106
  # Add Executive Summary
107
  doc.add_heading('Executive Summary', level=1)
108
- doc.add_paragraph("Based on the provided PDF content, the analysis has been carried out.")
109
-
 
 
110
  # Step 1: Text Analysis
111
  doc.add_heading('Step 1: Text Analysis', level=1)
112
- doc.add_paragraph(f"The extracted text from the PDF is as follows:\n{full_text[:1500]}") # Limit preview
113
 
114
- # Step 2: Assistant's Response
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
115
  doc.add_heading('Step 2: Assistant Analysis', level=1)
116
  doc.add_paragraph(f"The AI Assistant's insights are:\n{assistant_message}")
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  # Saving the DOCX file
119
  word_filename = "AI_Report_Formatted.docx"
120
  doc.save(word_filename)
@@ -130,3 +175,4 @@ if uploaded_file:
130
 
131
  except Exception as e:
132
  st.error(f"Error processing the chat: {str(e)}")
 
 
4
  from openai import OpenAI
5
  from docx import Document
6
  from docx.shared import Pt
7
+ from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
8
  import os
9
 
10
  # Set the page configuration
 
99
 
100
  # Generate Word (DOCX) file for download
101
  doc = Document()
102
+
103
  # Add a title and style
104
  title = doc.add_heading('AI Assistant Report', 0)
105
+ title.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER # Center align the title
106
+
107
  # Add Executive Summary
108
  doc.add_heading('Executive Summary', level=1)
109
+ doc.add_paragraph("Based on the provided PDF content, the analysis has been carried out. "
110
+ "Key insights and analysis are provided below, along with a variance analysis "
111
+ "and considerations for future actions.")
112
+
113
  # Step 1: Text Analysis
114
  doc.add_heading('Step 1: Text Analysis', level=1)
 
115
 
116
+ # Create a table for the extracted data
117
+ table = doc.add_table(rows=1, cols=6)
118
+ hdr_cells = table.rows[0].cells
119
+ hdr_cells[0].text = 'Sales (2025)'
120
+ hdr_cells[1].text = 'Sales (2024)'
121
+ hdr_cells[2].text = 'Sales Variance (%)'
122
+ hdr_cells[3].text = 'Gross Profit (2025)'
123
+ hdr_cells[4].text = 'Gross Profit (2024)'
124
+ hdr_cells[5].text = 'Gross Profit Variance (%)'
125
+
126
+ # Add sample row data (the actual data should be dynamically inserted here from the PDF)
127
+ row = table.add_row().cells
128
+ row[0].text = "1,392"
129
+ row[1].text = "1,400"
130
+ row[2].text = "-0.5"
131
+ row[3].text = "200"
132
+ row[4].text = "207"
133
+ row[5].text = "-3.0"
134
+
135
+ # Add Assistant's analysis
136
  doc.add_heading('Step 2: Assistant Analysis', level=1)
137
  doc.add_paragraph(f"The AI Assistant's insights are:\n{assistant_message}")
138
 
139
+ # Add tables for key insights like sales, gross profit, and variance analysis
140
+ doc.add_heading('Key Insights and Trends', level=2)
141
+ doc.add_paragraph("Here is a summary of the analysis based on the provided data:")
142
+
143
+ # Add another table for detailed analysis if necessary
144
+ detailed_table = doc.add_table(rows=1, cols=3)
145
+ detailed_hdr = detailed_table.rows[0].cells
146
+ detailed_hdr[0].text = 'Month'
147
+ detailed_hdr[1].text = 'Sales (ZAR)'
148
+ detailed_hdr[2].text = 'Gross Profit (ZAR)'
149
+
150
+ # Add sample data for detailed insights
151
+ month_data = [
152
+ ("February 2025", "1,392,000", "200,000"),
153
+ ("February 2024", "1,400,000", "207,000"),
154
+ ("Budgeted February 2025", "1,498,000", "221,000")
155
+ ]
156
+
157
+ for month, sales, profit in month_data:
158
+ row = detailed_table.add_row().cells
159
+ row[0].text = month
160
+ row[1].text = sales
161
+ row[2].text = profit
162
+
163
  # Saving the DOCX file
164
  word_filename = "AI_Report_Formatted.docx"
165
  doc.save(word_filename)
 
175
 
176
  except Exception as e:
177
  st.error(f"Error processing the chat: {str(e)}")
178
+