redxican commited on
Commit
0f40775
·
verified ·
1 Parent(s): d398022

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -33
app.py CHANGED
@@ -492,59 +492,63 @@ def export_bookmarked_models():
492
  return df.to_csv(index=False)
493
 
494
  def display_pdf_preview(file_path, model_name):
495
- """Display PDF inline without auto-downloading"""
496
  import os
497
 
498
- # Extract filename from the database path
499
  normalized_path = file_path.replace('\\', '/')
500
  pdf_filename = normalized_path.split('/')[-1]
501
 
502
- # Create direct Hugging Face URL for the PDF
503
  pdf_url = f"https://huggingface.co/spaces/TurboAir/TurboAirViewer/resolve/main/pdfs/{pdf_filename}"
504
 
505
- # Create columns for controls
506
  col1, col2, col3 = st.columns([2, 1, 1])
507
 
508
  with col1:
509
- # Only download when button is clicked - NOT automatic
510
- if st.button("📥 Download PDF", key=f"download_{model_name}", use_container_width=True, type="primary"):
511
- import requests
512
- try:
513
- response = requests.get(pdf_url, timeout=30)
514
- st.download_button(
515
- "💾 Click to Save",
516
- data=response.content,
517
- file_name=pdf_filename,
518
- mime="application/pdf",
519
- key=f"save_{model_name}"
520
- )
521
- except:
522
- st.error("Could not download PDF")
523
 
524
  with col2:
525
- st.success("✅ PDF ready to view")
526
 
527
  with col3:
528
  if st.button("❌ Close Preview", use_container_width=True):
529
  st.session_state[f'show_pdf_{model_name}'] = False
530
  st.rerun()
531
 
532
- # Display PDF inline WITHOUT downloading
533
  st.markdown("---")
534
 
535
- # Method 1: Google Docs Viewer (most reliable, no download)
536
- google_viewer_url = f"https://docs.google.com/viewer?url={pdf_url}&embedded=true"
537
-
538
- st.markdown(
539
- f'<iframe src="{google_viewer_url}" width="100%" height="800px" frameborder="0" style="border: 2px solid #4CAF50; border-radius: 8px;"></iframe>',
540
- unsafe_allow_html=True
541
- )
542
-
543
- # Method 2: If Google Viewer doesn't work, try direct embed (comment out Method 1 and uncomment below)
544
- # st.markdown(
545
- # f'<embed src="{pdf_url}#toolbar=0&navpanes=0&scrollbar=1" width="100%" height="800px" type="application/pdf" style="border: 2px solid #4CAF50; border-radius: 8px;">',
546
- # unsafe_allow_html=True
547
- # )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
548
 
549
  def get_high_accuracy_models(limit=8):
550
  """Get models with highest extraction quality"""
 
492
  return df.to_csv(index=False)
493
 
494
  def display_pdf_preview(file_path, model_name):
495
+ """Display PDF using Google Docs Viewer - most reliable method"""
496
  import os
497
 
498
+ # Extract filename
499
  normalized_path = file_path.replace('\\', '/')
500
  pdf_filename = normalized_path.split('/')[-1]
501
 
502
+ # Create direct URL
503
  pdf_url = f"https://huggingface.co/spaces/TurboAir/TurboAirViewer/resolve/main/pdfs/{pdf_filename}"
504
 
505
+ # Control buttons
506
  col1, col2, col3 = st.columns([2, 1, 1])
507
 
508
  with col1:
509
+ st.markdown(f'<a href="{pdf_url}" download="{pdf_filename}"><button style="width: 100%; padding: 0.5rem; background-color: #FF4B4B; color: white; border: none; border-radius: 5px; cursor: pointer;">📥 Download PDF</button></a>', unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
510
 
511
  with col2:
512
+ st.success("✅ PDF ready")
513
 
514
  with col3:
515
  if st.button("❌ Close Preview", use_container_width=True):
516
  st.session_state[f'show_pdf_{model_name}'] = False
517
  st.rerun()
518
 
519
+ # Display PDF - NO GREEN BORDER
520
  st.markdown("---")
521
 
522
+ # Method 1: Direct embed (try this first)
523
+ pdf_viewer = f"""
524
+ <embed
525
+ src="{pdf_url}#view=FitH&toolbar=0"
526
+ width="100%"
527
+ height="900px"
528
+ type="application/pdf">
529
+ """
530
+
531
+ # Method 2: If embed doesn't work, use iframe
532
+ # pdf_viewer = f"""
533
+ # <iframe
534
+ # src="{pdf_url}#view=FitH&toolbar=0"
535
+ # width="100%"
536
+ # height="900px"
537
+ # frameborder="0">
538
+ # </iframe>
539
+ # """
540
+
541
+ # Method 3: If neither works, use Google Docs
542
+ # pdf_viewer = f"""
543
+ # <iframe
544
+ # src="https://docs.google.com/viewer?url={pdf_url}&embedded=true"
545
+ # width="100%"
546
+ # height="900px"
547
+ # frameborder="0">
548
+ # </iframe>
549
+ # """
550
+
551
+ st.markdown(pdf_viewer, unsafe_allow_html=True)
552
 
553
  def get_high_accuracy_models(limit=8):
554
  """Get models with highest extraction quality"""