bluenevus commited on
Commit
b2d0f10
Β·
verified Β·
1 Parent(s): 1c7928f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -34
app.py CHANGED
@@ -227,38 +227,38 @@ def process_pdf(file_obj, progress=gr.Progress()) -> Tuple[Optional[str], str, s
227
  for file_path in output_files:
228
  zipf.write(file_path, file_path.name)
229
 
230
- # Generate statistics HTML
231
  stats_html = f"""
232
- <div style="padding: 20px; background: #f0f9ff; border-radius: 10px; margin: 10px 0;">
233
  <h3 style="color: #0369a1; margin-top: 0;">πŸ“Š Processing Results</h3>
234
  <table style="width: 100%; border-collapse: collapse;">
235
- <tr style="border-bottom: 1px solid #e0e0e0;">
236
- <td style="padding: 8px; font-weight: bold;">πŸ“„ Total Pages:</td>
237
- <td style="padding: 8px; text-align: right;">{stats['total_pages']}</td>
238
  </tr>
239
- <tr style="border-bottom: 1px solid #e0e0e0;">
240
- <td style="padding: 8px; font-weight: bold;">βœ… Segments Created:</td>
241
- <td style="padding: 8px; text-align: right;">{stats['segments_created']}</td>
242
  </tr>
243
- <tr style="border-bottom: 1px solid #e0e0e0;">
244
- <td style="padding: 8px; font-weight: bold;">πŸ“¦ Original Size:</td>
245
- <td style="padding: 8px; text-align: right;">{stats['original_size_mb']:.2f} MB</td>
246
  </tr>
247
- <tr style="border-bottom: 1px solid #e0e0e0;">
248
- <td style="padding: 8px; font-weight: bold;">πŸ“ Total Output Size:</td>
249
- <td style="padding: 8px; text-align: right;">{stats['total_output_size_mb']:.2f} MB</td>
250
  </tr>
251
  <tr>
252
- <td style="padding: 8px; font-weight: bold;">πŸ’Ύ Compression Ratio:</td>
253
- <td style="padding: 8px; text-align: right;">
254
- {((1 - stats['total_output_size_mb'] / stats['original_size_mb']) * 100):.1f}%
255
  </td>
256
  </tr>
257
  </table>
258
  <p style="margin-top: 15px; color: #059669; font-weight: bold;">
259
  ✨ Your file has been split successfully!
260
  </p>
261
- <p style="margin-top: 10px; color: #6b7280; font-size: 0.9em;">
262
  ⏱️ Files will be automatically deleted after {CLEANUP_AFTER_MINUTES} minutes
263
  </p>
264
  </div>
@@ -280,19 +280,52 @@ def process_pdf(file_obj, progress=gr.Progress()) -> Tuple[Optional[str], str, s
280
  pass
281
  return None, "", f"❌ Error: {str(e)}"
282
 
283
- # Create Gradio interface
284
- with gr.Blocks(
285
- title="PDF Splitter - Fast & Simple",
286
- theme=gr.themes.Soft(),
287
- css="""
288
  .gradio-container {
289
  max-width: 800px;
290
  margin: auto;
291
  }
292
- footer {
293
- display: none !important;
 
 
294
  }
295
- """
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
296
  ) as app:
297
 
298
  gr.Markdown("""
@@ -316,25 +349,29 @@ with gr.Blocks(
316
  file_input = gr.File(
317
  label="Upload PDF",
318
  file_types=[".pdf"],
319
- type="filepath"
 
320
  )
321
 
322
  split_btn = gr.Button(
323
  "πŸš€ Split PDF",
324
  variant="primary",
325
- size="lg"
 
326
  )
327
 
328
  with gr.Row():
329
- status_text = gr.Markdown("Ready to process your PDF...")
330
 
331
  with gr.Row():
332
- stats_output = gr.HTML()
333
 
334
  with gr.Row():
335
  download_file = gr.File(
336
  label="πŸ“¦ Download ZIP",
337
- visible=True
 
 
338
  )
339
 
340
  # Handle processing
@@ -344,7 +381,7 @@ with gr.Blocks(
344
  outputs=[download_file, stats_output, status_text]
345
  )
346
 
347
- # Add examples
348
  gr.Markdown("""
349
  ---
350
  ### πŸ’‘ Features:
@@ -357,12 +394,13 @@ with gr.Blocks(
357
  ### πŸ”’ Privacy:
358
  All uploaded files are automatically deleted after processing and download.
359
  No files are stored permanently on the server.
360
- """)
361
 
362
  # Launch the app
363
  if __name__ == "__main__":
364
  app.launch(
365
  server_name="0.0.0.0",
366
  server_port=7860,
367
- share=False
 
368
  )
 
227
  for file_path in output_files:
228
  zipf.write(file_path, file_path.name)
229
 
230
+ # Generate statistics HTML with fixed styling
231
  stats_html = f"""
232
+ <div style="padding: 20px; background: #e8f4f8; border-radius: 10px; margin: 10px 0; border: 1px solid #0369a1;">
233
  <h3 style="color: #0369a1; margin-top: 0;">πŸ“Š Processing Results</h3>
234
  <table style="width: 100%; border-collapse: collapse;">
235
+ <tr style="border-bottom: 1px solid #94a3b8;">
236
+ <td style="padding: 8px; font-weight: bold; color: #1e293b;">πŸ“„ Total Pages:</td>
237
+ <td style="padding: 8px; text-align: right; color: #334155;">{stats['total_pages']}</td>
238
  </tr>
239
+ <tr style="border-bottom: 1px solid #94a3b8;">
240
+ <td style="padding: 8px; font-weight: bold; color: #1e293b;">βœ… Segments Created:</td>
241
+ <td style="padding: 8px; text-align: right; color: #334155;">{stats['segments_created']}</td>
242
  </tr>
243
+ <tr style="border-bottom: 1px solid #94a3b8;">
244
+ <td style="padding: 8px; font-weight: bold; color: #1e293b;">πŸ“¦ Original Size:</td>
245
+ <td style="padding: 8px; text-align: right; color: #334155;">{stats['original_size_mb']:.2f} MB</td>
246
  </tr>
247
+ <tr style="border-bottom: 1px solid #94a3b8;">
248
+ <td style="padding: 8px; font-weight: bold; color: #1e293b;">πŸ“ Total Output Size:</td>
249
+ <td style="padding: 8px; text-align: right; color: #334155;">{stats['total_output_size_mb']:.2f} MB</td>
250
  </tr>
251
  <tr>
252
+ <td style="padding: 8px; font-weight: bold; color: #1e293b;">πŸ’Ύ Compression Ratio:</td>
253
+ <td style="padding: 8px; text-align: right; color: #334155;">
254
+ {((1 - stats['total_output_size_mb'] / stats['original_size_mb']) * 100) if stats['original_size_mb'] > 0 else 0:.1f}%
255
  </td>
256
  </tr>
257
  </table>
258
  <p style="margin-top: 15px; color: #059669; font-weight: bold;">
259
  ✨ Your file has been split successfully!
260
  </p>
261
+ <p style="margin-top: 10px; color: #64748b; font-size: 0.9em;">
262
  ⏱️ Files will be automatically deleted after {CLEANUP_AFTER_MINUTES} minutes
263
  </p>
264
  </div>
 
280
  pass
281
  return None, "", f"❌ Error: {str(e)}"
282
 
283
+ # Custom CSS to fix text visibility and button styling
284
+ custom_css = """
 
 
 
285
  .gradio-container {
286
  max-width: 800px;
287
  margin: auto;
288
  }
289
+
290
+ /* Fix text colors to ensure visibility */
291
+ .markdown-text, .markdown-text p, .markdown-text h1, .markdown-text h2, .markdown-text h3 {
292
+ color: #1f2937 !important;
293
  }
294
+
295
+ /* Ensure download button is styled properly */
296
+ .download-button, button[aria-label*="Download"] {
297
+ background-color: #3b82f6 !important;
298
+ color: white !important;
299
+ cursor: pointer !important;
300
+ }
301
+
302
+ .download-button:hover, button[aria-label*="Download"]:hover {
303
+ background-color: #2563eb !important;
304
+ }
305
+
306
+ /* Fix file component styling */
307
+ .file-preview {
308
+ background-color: #f3f4f6 !important;
309
+ border: 1px solid #d1d5db !important;
310
+ }
311
+
312
+ /* Ensure all text is visible */
313
+ label, .label-text {
314
+ color: #374151 !important;
315
+ }
316
+
317
+ /* Status text visibility */
318
+ .status-text {
319
+ color: #1f2937 !important;
320
+ font-weight: 500;
321
+ }
322
+ """
323
+
324
+ # Create Gradio interface with fixed theme
325
+ with gr.Blocks(
326
+ title="PDF Splitter - Fast & Simple",
327
+ theme=gr.themes.Base(), # Using Base theme for better control
328
+ css=custom_css
329
  ) as app:
330
 
331
  gr.Markdown("""
 
349
  file_input = gr.File(
350
  label="Upload PDF",
351
  file_types=[".pdf"],
352
+ type="filepath",
353
+ elem_classes="file-upload"
354
  )
355
 
356
  split_btn = gr.Button(
357
  "πŸš€ Split PDF",
358
  variant="primary",
359
+ size="lg",
360
+ elem_classes="split-button"
361
  )
362
 
363
  with gr.Row():
364
+ status_text = gr.Markdown("Ready to process your PDF...", elem_classes="status-text")
365
 
366
  with gr.Row():
367
+ stats_output = gr.HTML(elem_classes="stats-output")
368
 
369
  with gr.Row():
370
  download_file = gr.File(
371
  label="πŸ“¦ Download ZIP",
372
+ visible=True,
373
+ elem_classes="download-section",
374
+ interactive=False # Make it non-interactive until file is ready
375
  )
376
 
377
  # Handle processing
 
381
  outputs=[download_file, stats_output, status_text]
382
  )
383
 
384
+ # Add features with proper styling
385
  gr.Markdown("""
386
  ---
387
  ### πŸ’‘ Features:
 
394
  ### πŸ”’ Privacy:
395
  All uploaded files are automatically deleted after processing and download.
396
  No files are stored permanently on the server.
397
+ """, elem_classes="features-section")
398
 
399
  # Launch the app
400
  if __name__ == "__main__":
401
  app.launch(
402
  server_name="0.0.0.0",
403
  server_port=7860,
404
+ share=False,
405
+ show_error=True
406
  )