Spaces:
No application file
No application file
Update app.py
Browse files
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
|
| 496 |
import os
|
| 497 |
|
| 498 |
-
# Extract filename
|
| 499 |
normalized_path = file_path.replace('\\', '/')
|
| 500 |
pdf_filename = normalized_path.split('/')[-1]
|
| 501 |
|
| 502 |
-
# Create direct
|
| 503 |
pdf_url = f"https://huggingface.co/spaces/TurboAir/TurboAirViewer/resolve/main/pdfs/{pdf_filename}"
|
| 504 |
|
| 505 |
-
#
|
| 506 |
col1, col2, col3 = st.columns([2, 1, 1])
|
| 507 |
|
| 508 |
with col1:
|
| 509 |
-
|
| 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
|
| 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
|
| 533 |
st.markdown("---")
|
| 534 |
|
| 535 |
-
# Method 1:
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
#
|
| 545 |
-
#
|
| 546 |
-
#
|
| 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"""
|