Spaces:
Runtime error
Runtime error
import gradio as gr | |
from fpdf import FPDF | |
from mistletoe import markdown | |
from research_assistant.app_logging import app_logger | |
from research_assistant.pipeline.articleSummarization import ArticleSummarization | |
def process_file(file): | |
try: | |
app_logger.info(f"Processing file: {file}") | |
summary_pipeline = ArticleSummarization(file) | |
summary = summary_pipeline.get_summary() | |
word_count = len(summary.split()) | |
except Exception as e: | |
summary = f"An error occurred: {e}" | |
word_count = 0 | |
return summary, word_count | |
def generate_pdf(summary): | |
pdf = FPDF() | |
pdf.add_page() | |
pdf.set_auto_page_break(auto=True, margin=15) | |
pdf.set_font("Helvetica", size=12) | |
try: | |
html_content = markdown(summary) | |
pdf.write_html(html_content) | |
except Exception as e: | |
app_logger.error(f"Error generating PDF: {e}") | |
pdf.write(5, "Error generating PDF content.") | |
pdf_output_path = "summary.pdf" | |
pdf.output(name=pdf_output_path) | |
return pdf_output_path | |
def process_and_generate_pdf(file): | |
summary, wordcount = process_file(file) | |
pdf_output_path = generate_pdf(summary) | |
return summary, wordcount, pdf_output_path | |
iface = gr.Interface( | |
fn=process_and_generate_pdf, | |
inputs=gr.File(label="Upload PDF", type="filepath"), | |
outputs=[ | |
gr.Textbox(label="Summary"), | |
gr.Number(label="Word Count"), | |
gr.File(label="Download PDF"), | |
], | |
title="Research Assistant Summarizer", | |
description="Summarize your research paper.", | |
theme=gr.themes.Default(), | |
) | |
if __name__ == "__main__": | |
iface.launch(share=True) | |