Spaces:
Runtime error
Runtime error
| from utils import * | |
| import gradio as gr | |
| from dotenv import load_dotenv | |
| import os | |
| load_dotenv() | |
| # Define file paths | |
| reference_file_path = "./data/reference.xlsx" | |
| pdf_directory = "./data/pdf/" | |
| # Check if reference file exists | |
| if not os.path.exists(reference_file_path): | |
| raise FileNotFoundError("Reference file not found. Please ensure 'data/reference.xlsx' exists in the workspace.") | |
| # Load the reference data from Excel | |
| reference = pd.read_excel(reference_file_path) | |
| paper_summaries = process_all_papers(pdf_directory, reference=reference) | |
| # Define the Gradio function to process and display summaries | |
| def display_summaries(): | |
| global paper_summaries | |
| # Format the summaries for display in Gradio | |
| formatted_summary = "" | |
| for summary in paper_summaries: | |
| formatted_summary += ( | |
| f"Paper ID: {summary['ID']}\n" | |
| f"Citation: {summary['Citation']}\n" | |
| f"Context: {summary['Context']}\n" | |
| f"Research Question and Findings: {summary['Research Question and Findings']}\n" | |
| f"Theme of Research: {summary['Theme of Research']}\n" | |
| f"Method: {summary['Method']}\n" | |
| f"Contribution: {summary['Contribution']}\n" | |
| f"Future Potential and Limitations: {summary['Future Potential and Limitations']}\n\n" | |
| "------------------------------------------\n\n" | |
| ) | |
| return formatted_summary | |
| # Gradio function to get user input and display summaries based on criteria | |
| def retrieve_and_display_search_results(user_input): | |
| global paper_summaries | |
| # Call the search and summarize function | |
| cohesive_summary, formatted_citations = search_and_summarize_with_llm(paper_summaries, user_input) | |
| # Return combined summary and citations | |
| return cohesive_summary + "\n\n" + formatted_citations | |
| # Create Gradio interface | |
| with gr.Blocks() as demo: | |
| gr.Markdown("# Academic Paper Summarization Tool") | |
| gr.Markdown("Click 'Begin Summarization' to process and summarize the 32 papers.") | |
| summary_output = gr.Textbox( | |
| label="Summarization Output", | |
| placeholder="Summaries will appear here after processing...", | |
| lines=30, | |
| interactive=False | |
| ) | |
| begin_button = gr.Button("Begin Summarization") | |
| begin_button.click(fn=display_summaries, inputs=None, outputs=summary_output) | |
| gr.Markdown("# Research Summarization Tool") | |
| gr.Markdown("Type your search criteria below (e.g., 'I want all research about human VS AI and empirical research')") | |
| user_input = gr.Textbox(label="Search Criteria", placeholder="Enter your search criteria here...") | |
| search_button = gr.Button("Search Relevant Articles") | |
| search_output = gr.Textbox( | |
| label="Search Results", | |
| placeholder="Results of search will appear here...", | |
| lines=30, | |
| interactive=False | |
| ) | |
| search_button.click(fn=retrieve_and_display_search_results, inputs=user_input, outputs=search_output) | |
| # Run the app | |
| demo.launch() | |