shukdevdatta123 commited on
Commit
491c5fc
·
verified ·
1 Parent(s): ad1955b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -48
app.py CHANGED
@@ -4,7 +4,6 @@ import fitz # PyMuPDF for PDF processing
4
  import os
5
  import tempfile
6
  import base64
7
- import pdfkit
8
  from datetime import datetime
9
 
10
  # Variable to store API key
@@ -301,42 +300,6 @@ def create_html_download_link(html_content):
301
 
302
  return download_link
303
 
304
- # Function to create a downloadable PDF file
305
- def create_pdf_download_link(html_content):
306
- if not html_content or "<div style=\"color: red; padding: 20px;" in html_content or "Please upload at least one PDF file" in html_content:
307
- return None
308
-
309
- try:
310
- # Create timestamp for the filename
311
- timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
312
- pdf_filename = f"systematic_review_{timestamp}.pdf"
313
-
314
- # Create a temporary file for the PDF
315
- with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_pdf:
316
- pdf_path = tmp_pdf.name
317
-
318
- # Convert HTML to PDF
319
- pdfkit.from_string(html_content, pdf_path)
320
-
321
- # Read the PDF file and encode it
322
- with open(pdf_path, "rb") as pdf_file:
323
- pdf_data = pdf_file.read()
324
-
325
- # Encode the PDF content for download
326
- b64_pdf = base64.b64encode(pdf_data).decode()
327
- download_link = f'<a href="data:application/pdf;base64,{b64_pdf}" download="{pdf_filename}" class="download-button">Download PDF</a>'
328
-
329
- # Clean up the temporary file
330
- try:
331
- os.remove(pdf_path)
332
- except:
333
- pass
334
-
335
- return download_link
336
-
337
- except Exception as e:
338
- return f'<div style="color: red; margin-top: 10px;">PDF generation error: {str(e)}</div>'
339
-
340
  # Add CSS styling for the Gradio interface
341
  custom_css = """
342
  <style>
@@ -428,7 +391,7 @@ custom_css = """
428
  margin-bottom: 20px;
429
  }
430
 
431
- /* Download Buttons */
432
  .download-button {
433
  display: inline-block;
434
  background: linear-gradient(135deg, #4a00e0 0%, #8e2de2 100%);
@@ -437,7 +400,6 @@ custom_css = """
437
  padding: 8px 16px;
438
  border-radius: 4px;
439
  text-decoration: none;
440
- margin-right: 10px;
441
  margin-bottom: 10px;
442
  transition: all 0.3s ease;
443
  }
@@ -478,7 +440,7 @@ with gr.Blocks(css=custom_css) as demo:
478
  3. Enter your review question or topic
479
  4. Check the "Include Tables" option if you want the review to include comparison tables
480
  5. Click "Generate Systematic Review" to start the process
481
- 6. After generation, you can download the review as HTML or PDF
482
 
483
  ### Tips for Best Results:
484
  - Upload papers that are related to the same research topic or field
@@ -509,7 +471,7 @@ with gr.Blocks(css=custom_css) as demo:
509
  include_tables = gr.Checkbox(label="Include Comparison Tables", value=True)
510
  generate_button = gr.Button("Generate Systematic Review", elem_id="generate_button", size="large")
511
 
512
- # Download links container
513
  download_html_output = gr.HTML(label="Download Options")
514
 
515
  # Output with improved styling
@@ -554,17 +516,15 @@ with gr.Blocks(css=custom_css) as demo:
554
  # Generate review
555
  review = generate_systematic_review(saved_paths, question, include_tables)
556
 
557
- # Create download links
558
  html_link = create_html_download_link(review)
559
- pdf_link = create_pdf_download_link(review)
560
 
561
- # Create combined download links HTML
562
- download_links = f"""
563
  <div id="download-container">
564
  <div>
565
- <h3>Download Options:</h3>
566
  {html_link or ""}
567
- {pdf_link or ""}
568
  </div>
569
  </div>
570
  """
@@ -576,7 +536,7 @@ with gr.Blocks(css=custom_css) as demo:
576
  except:
577
  pass
578
 
579
- yield review, download_links
580
 
581
  generate_button.click(
582
  process_files_and_generate_review,
 
4
  import os
5
  import tempfile
6
  import base64
 
7
  from datetime import datetime
8
 
9
  # Variable to store API key
 
300
 
301
  return download_link
302
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
  # Add CSS styling for the Gradio interface
304
  custom_css = """
305
  <style>
 
391
  margin-bottom: 20px;
392
  }
393
 
394
+ /* Download Button */
395
  .download-button {
396
  display: inline-block;
397
  background: linear-gradient(135deg, #4a00e0 0%, #8e2de2 100%);
 
400
  padding: 8px 16px;
401
  border-radius: 4px;
402
  text-decoration: none;
 
403
  margin-bottom: 10px;
404
  transition: all 0.3s ease;
405
  }
 
440
  3. Enter your review question or topic
441
  4. Check the "Include Tables" option if you want the review to include comparison tables
442
  5. Click "Generate Systematic Review" to start the process
443
+ 6. After generation, you can download the review as HTML
444
 
445
  ### Tips for Best Results:
446
  - Upload papers that are related to the same research topic or field
 
471
  include_tables = gr.Checkbox(label="Include Comparison Tables", value=True)
472
  generate_button = gr.Button("Generate Systematic Review", elem_id="generate_button", size="large")
473
 
474
+ # Download link container
475
  download_html_output = gr.HTML(label="Download Options")
476
 
477
  # Output with improved styling
 
516
  # Generate review
517
  review = generate_systematic_review(saved_paths, question, include_tables)
518
 
519
+ # Create HTML download link
520
  html_link = create_html_download_link(review)
 
521
 
522
+ # Create download link HTML
523
+ download_link = f"""
524
  <div id="download-container">
525
  <div>
526
+ <h3>Download Option:</h3>
527
  {html_link or ""}
 
528
  </div>
529
  </div>
530
  """
 
536
  except:
537
  pass
538
 
539
+ yield review, download_link
540
 
541
  generate_button.click(
542
  process_files_and_generate_review,