IAMTFRMZA commited on
Commit
13d1927
·
verified ·
1 Parent(s): de67278
Files changed (1) hide show
  1. app.py +30 -64
app.py CHANGED
@@ -1,30 +1,30 @@
1
  import streamlit as st
2
- from openai import OpenAI
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
10
- st.set_page_config(page_title="LOR Chat ReportAi")
11
 
12
  # Title and caption
13
- st.title("LOR Chat Report Ai Assistant")
14
- st.caption("Chat with an AI Assistant on your LOR Chat Report")
15
 
16
  # Sidebar for API Key input
17
  with st.sidebar:
18
- OPENAI_API_KEY = st.text_input("Enter your C2 Group of Technologies Access Key", type="password")
19
 
20
  # Check for valid API key
21
  if OPENAI_API_KEY:
22
  client = OpenAI(api_key=OPENAI_API_KEY)
23
  else:
24
- st.error("Please enter your C2 Group of Technologies Access Key to continue.")
25
  st.stop()
26
 
27
- ASSISTANT_ID = "asst_lLRD8YOe64ZZ3eYBGP1Ew5y9"
28
 
29
  # Initialize session state for chat history
30
  if "messages" not in st.session_state:
@@ -41,16 +41,23 @@ for message in st.session_state.messages:
41
  st.chat_message(role).write(content)
42
 
43
  # Process user input
44
- uploaded_file = st.file_uploader("Upload Excel file", type=["xlsx"])
45
 
46
  if uploaded_file:
47
- # Read the Excel file
48
- df = pd.read_excel(uploaded_file)
49
- st.write("Data from uploaded Excel file:")
50
- st.write(df)
51
-
52
- # Process user input
53
- prompt = f"Please analyze the following data: {df.head()}"
 
 
 
 
 
 
 
54
  st.session_state.messages.append({"role": "user", "content": prompt})
55
  st.chat_message("user").write(prompt)
56
 
@@ -98,56 +105,15 @@ if uploaded_file:
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"
 
1
  import streamlit as st
 
2
  import time
3
+ import fitz # PyMuPDF for PDF processing
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
10
+ st.set_page_config(page_title="Report Generation AI")
11
 
12
  # Title and caption
13
+ st.title("AI Report Generator")
14
+ st.caption("Generate Professional Reports from PDF Documents")
15
 
16
  # Sidebar for API Key input
17
  with st.sidebar:
18
+ OPENAI_API_KEY = st.text_input("Enter your Access Key", type="password")
19
 
20
  # Check for valid API key
21
  if OPENAI_API_KEY:
22
  client = OpenAI(api_key=OPENAI_API_KEY)
23
  else:
24
+ st.error("Please enter your Access Key to continue.")
25
  st.stop()
26
 
27
+ ASSISTANT_ID = "asst_d68xqxiRtvYkmewBPugwZaGx"
28
 
29
  # Initialize session state for chat history
30
  if "messages" not in st.session_state:
 
41
  st.chat_message(role).write(content)
42
 
43
  # Process user input
44
+ uploaded_file = st.file_uploader("Upload PDF file", type=["pdf"])
45
 
46
  if uploaded_file:
47
+ # Read the PDF file
48
+ pdf_document = fitz.open(uploaded_file)
49
+ full_text = ""
50
+
51
+ # Extract text from each page
52
+ for page_num in range(pdf_document.page_count):
53
+ page = pdf_document.load_page(page_num)
54
+ full_text += page.get_text()
55
+
56
+ st.write("Text extracted from PDF:")
57
+ st.text_area("Extracted Text", full_text, height=300)
58
+
59
+ # Process user input for assistant
60
+ prompt = f"Please analyze the following text from the PDF: {full_text[:1000]}" # Limit to the first 1000 chars for clarity
61
  st.session_state.messages.append({"role": "user", "content": prompt})
62
  st.chat_message("user").write(prompt)
63
 
 
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"