File size: 3,092 Bytes
27b16dd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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()