Rauhan commited on
Commit
a4cb6f8
Β·
1 Parent(s): f081c86

UPDATE: main.py

Browse files
Files changed (1) hide show
  1. main.py +91 -38
main.py CHANGED
@@ -15,37 +15,71 @@ import time
15
 
16
  # Configure the page
17
  st.set_page_config(
18
- page_title="PDF Summarizer",
19
- page_icon=None,
20
  layout="wide"
21
  )
22
 
23
- # Initialize the pipeline
24
- pipeline = Pipeline()
25
-
26
  # Custom styling
27
  st.markdown("""
28
  <style>
 
 
 
 
 
29
  .main-header {
30
- font-size: 2.5rem;
31
- color: #1E88E5;
32
- margin-bottom: 2rem;
 
 
 
33
  }
 
34
  .summary-header {
35
  font-size: 1.8rem;
36
- color: #2E7D32;
37
- margin: 1.5rem 0;
 
 
 
38
  }
 
39
  .status-container {
40
- padding: 1rem;
41
- border-radius: 0.5rem;
42
- background-color: #f0f2f6;
43
- margin: 1rem 0;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  }
45
  </style>
46
  """, unsafe_allow_html=True)
47
 
48
- # Cache the font download
 
 
 
49
  @st.cache_resource(show_spinner=False)
50
  def getDejaVuFontPath():
51
  fontUrl = "https://github.com/senotrusov/dejavu-fonts-ttf/raw/refs/heads/master/ttf/DejaVuSans.ttf"
@@ -55,12 +89,12 @@ def getDejaVuFontPath():
55
  tempFontFile.close()
56
  return tempFontFile.name
57
 
58
- # Cache the summary generation
59
  @st.cache_data(show_spinner=False, ttl=3600)
60
  def generateSummary(_pipeline, pdfBytes):
61
  return pipeline.run(pdfBytes)
62
 
63
- # Cache the PDF generation
64
  @st.cache_data(show_spinner=False, ttl=3600)
65
  def generatePdfBytes(summary, fontPath):
66
  buffer = BytesIO()
@@ -92,65 +126,84 @@ def generatePdfBytes(summary, fontPath):
92
 
93
  # Sidebar
94
  with st.sidebar:
95
- st.markdown("### Upload PDF")
96
- uploadedFile = st.file_uploader("Choose your PDF file", type=["pdf"])
97
 
98
  if uploadedFile:
 
99
  pdfDetails = {
100
- "File Name": uploadedFile.name,
101
- "File Size": f"{round(len(uploadedFile.getvalue()) / 1024, 2)} KB",
102
- "Upload Time": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
103
  }
104
-
105
- st.markdown("### PDF Details")
106
  for key, value in pdfDetails.items():
107
- st.write(f"**{key}:** {value}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  # Main content
110
- st.markdown("<h1 class='main-header'>PDF Summarizer</h1>", unsafe_allow_html=True)
111
- st.write("This application generates a concise summary from your uploaded PDF document. Upload a file to get started.")
112
 
113
  if uploadedFile:
114
  statusContainer = st.empty()
115
  summaryContainer = st.empty()
116
 
117
  with statusContainer.container():
118
- st.markdown("### Processing Status")
 
119
  statusBox = st.empty()
120
 
121
  try:
122
  startTime = time.time()
123
- statusBox.info("Reading PDF file...")
124
  pdfBytes = uploadedFile.getvalue()
125
  readDuration = time.time() - startTime
126
- statusBox.success(f"PDF file read successfully ({readDuration:.2f}s)")
127
 
128
- statusBox.info("Generating summary...")
129
  summary = generateSummary(pipeline, pdfBytes)
130
  totalTime = time.time() - startTime
131
 
132
  if summary:
133
- statusBox.success(f"Summary generated successfully (Total time: {totalTime:.2f}s)")
 
134
 
135
  with summaryContainer.container():
136
- st.markdown("<h2 class='summary-header'>Generated Summary</h2>", unsafe_allow_html=True)
137
  st.markdown(summary)
 
138
  try:
139
  fontPath = getDejaVuFontPath()
140
  pdfBytesOut = generatePdfBytes(summary, fontPath)
141
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
142
 
143
  st.download_button(
144
- label="Download Summary as PDF",
145
  data=pdfBytesOut,
146
  file_name=f"summary_{timestamp}.pdf",
147
  mime="application/pdf"
148
  )
149
  except Exception as e:
150
- st.error(f"Error creating PDF: {str(e)}")
151
  else:
152
- statusBox.error("Failed to generate summary. Please try again.")
153
  except Exception as e:
154
- statusBox.error(f"Error processing PDF: {str(e)}")
155
  else:
156
- st.info("Please upload a PDF file using the sidebar to get started.")
 
15
 
16
  # Configure the page
17
  st.set_page_config(
18
+ page_title="AlphaExtract β€” Your AI-powered PDF Summarizer",
19
+ page_icon="πŸ“ˆ",
20
  layout="wide"
21
  )
22
 
 
 
 
23
  # Custom styling
24
  st.markdown("""
25
  <style>
26
+ html, body, [class*="css"] {
27
+ font-family: 'Segoe UI', sans-serif;
28
+ background-color: #f9fbfd;
29
+ }
30
+
31
  .main-header {
32
+ font-size: 3rem;
33
+ color: #0A66C2;
34
+ font-weight: 700;
35
+ text-align: center;
36
+ margin-top: 1rem;
37
+ margin-bottom: 2.5rem;
38
  }
39
+
40
  .summary-header {
41
  font-size: 1.8rem;
42
+ color: #00695C;
43
+ font-weight: 600;
44
+ border-bottom: 2px solid #e0e0e0;
45
+ padding-bottom: 0.5rem;
46
+ margin-top: 2rem;
47
  }
48
+
49
  .status-container {
50
+ background: rgba(255, 255, 255, 0.7);
51
+ backdrop-filter: blur(10px);
52
+ border: 1px solid #E3EAF2;
53
+ box-shadow: 0px 4px 12px rgba(0,0,0,0.05);
54
+ border-radius: 10px;
55
+ padding: 1.2rem 1.5rem;
56
+ margin: 1.5rem 0;
57
+ }
58
+
59
+ .stDownloadButton > button {
60
+ background-color: #0A66C2;
61
+ color: white;
62
+ font-weight: bold;
63
+ border-radius: 8px;
64
+ padding: 0.6rem 1.2rem;
65
+ margin-top: 1rem;
66
+ transition: background-color 0.3s ease;
67
+ }
68
+
69
+ .stDownloadButton > button:hover {
70
+ background-color: #084B8A;
71
+ }
72
+
73
+ .sidebar .sidebar-content {
74
+ background-color: #ffffff;
75
  }
76
  </style>
77
  """, unsafe_allow_html=True)
78
 
79
+ # Initialize the pipeline
80
+ pipeline = Pipeline()
81
+
82
+ # Cache font download
83
  @st.cache_resource(show_spinner=False)
84
  def getDejaVuFontPath():
85
  fontUrl = "https://github.com/senotrusov/dejavu-fonts-ttf/raw/refs/heads/master/ttf/DejaVuSans.ttf"
 
89
  tempFontFile.close()
90
  return tempFontFile.name
91
 
92
+ # Cache summary generation
93
  @st.cache_data(show_spinner=False, ttl=3600)
94
  def generateSummary(_pipeline, pdfBytes):
95
  return pipeline.run(pdfBytes)
96
 
97
+ # Cache PDF generation
98
  @st.cache_data(show_spinner=False, ttl=3600)
99
  def generatePdfBytes(summary, fontPath):
100
  buffer = BytesIO()
 
126
 
127
  # Sidebar
128
  with st.sidebar:
129
+ st.markdown("## πŸ“„ Upload PDF")
130
+ uploadedFile = st.file_uploader("Drop your financial PDF here", type=["pdf"])
131
 
132
  if uploadedFile:
133
+ st.markdown("### πŸ” File Info")
134
  pdfDetails = {
135
+ "πŸ“ File Name": uploadedFile.name,
136
+ "πŸ“¦ Size": f"{round(len(uploadedFile.getvalue()) / 1024, 2)} KB",
137
+ "⏰ Uploaded": datetime.now().strftime("%Y-%m-%d %H:%M:%S")
138
  }
 
 
139
  for key, value in pdfDetails.items():
140
+ st.write(f"**{key}**: {value}")
141
+
142
+ st.markdown("---")
143
+ st.markdown("#### βš™οΈ Powered By")
144
+
145
+ col1, col2 = st.columns([1, 5])
146
+ with col1:
147
+ st.image("mnt/data/d0758679-eff1-46c8-9e0c-47d782259782.png", width=45)
148
+
149
+ with col2:
150
+ st.markdown("""
151
+ <div style='font-size: 0.9rem; line-height: 1.4;'>
152
+ Inference by <strong>Groq</strong><br>
153
+ using Meta’s <strong>LLaMA 4 MOE Maverick</strong><br>
154
+ for blazing-fast, high-precision summaries.
155
+ </div>
156
+ """, unsafe_allow_html=True)
157
+
158
 
159
  # Main content
160
+ st.markdown("<h1 class='main-header'>Welcome to <span style='color:#2E7D32'>AlphaExtract</span></h1>", unsafe_allow_html=True)
161
+ st.write("Upload a PDF to instantly receive a professional-grade analytical summary.")
162
 
163
  if uploadedFile:
164
  statusContainer = st.empty()
165
  summaryContainer = st.empty()
166
 
167
  with statusContainer.container():
168
+ st.markdown("<div class='status-container'>", unsafe_allow_html=True)
169
+ st.markdown("### ⏳ Processing Status")
170
  statusBox = st.empty()
171
 
172
  try:
173
  startTime = time.time()
174
+ statusBox.info("πŸ“˜ Reading PDF file...")
175
  pdfBytes = uploadedFile.getvalue()
176
  readDuration = time.time() - startTime
177
+ statusBox.success(f"βœ… PDF file read successfully ({readDuration:.2f}s)")
178
 
179
+ statusBox.info("🧠 Generating summary...")
180
  summary = generateSummary(pipeline, pdfBytes)
181
  totalTime = time.time() - startTime
182
 
183
  if summary:
184
+ statusBox.success(f"βœ… Summary generated successfully (Total time: {totalTime:.2f}s)")
185
+ st.markdown("</div>", unsafe_allow_html=True)
186
 
187
  with summaryContainer.container():
188
+ st.markdown("<h2 class='summary-header'>πŸ“Š Generated Summary</h2>", unsafe_allow_html=True)
189
  st.markdown(summary)
190
+
191
  try:
192
  fontPath = getDejaVuFontPath()
193
  pdfBytesOut = generatePdfBytes(summary, fontPath)
194
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
195
 
196
  st.download_button(
197
+ label="⬇️ Download Summary as PDF",
198
  data=pdfBytesOut,
199
  file_name=f"summary_{timestamp}.pdf",
200
  mime="application/pdf"
201
  )
202
  except Exception as e:
203
+ st.error(f"❌ Error creating PDF: {str(e)}")
204
  else:
205
+ statusBox.error("❌ Failed to generate summary. Please try again.")
206
  except Exception as e:
207
+ statusBox.error(f"❌ Error processing PDF: {str(e)}")
208
  else:
209
+ st.info("πŸš€ Please upload a PDF file using the sidebar to get started.")