File size: 1,734 Bytes
0e9a6da
 
 
 
c4d8214
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0e9a6da
c4d8214
 
 
 
 
 
0e9a6da
c4d8214
 
 
 
 
 
 
 
 
 
 
 
 
 
0e9a6da
c4d8214
 
 
 
 
 
 
 
0e9a6da
 
 
 
 
 
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
import gradio as gr
from src.rag.pipeline import answer_question


def format_answer(question: str) -> tuple[str, str]:
    """Format answer with citations."""
    answer, citations = answer_question(question)
    
    # Format citations
    if citations:
        citations_text = "\n\n### πŸ“š Sources:\n"
        for i, citation in enumerate(citations, 1):
            citations_text += f"{i}. **{citation['title']}** ({citation['year']})\n"
    else:
        citations_text = ""
    
    return answer, citations_text


def run_gradio():
    with gr.Blocks(title="PaperMate", theme=gr.themes.Soft()) as demo:
        gr.Markdown(
            """
            # πŸ“„ PaperMate β€” Research Paper Q&A Assistant
            Ask questions about research papers and get answers backed by scientific literature.
            """
        )
        
        with gr.Row():
            with gr.Column():
                question = gr.Textbox(
                    label="Your Question",
                    placeholder="e.g., What techniques are used to handle out-of-vocabulary words in NLP?",
                    lines=3,
                )
                btn = gr.Button("πŸ” Search & Answer", variant="primary")
        
        with gr.Row():
            with gr.Column():
                output = gr.Textbox(label="Answer", lines=10, max_lines=20)
                citations = gr.Markdown(label="Sources")

        btn.click(fn=format_answer, inputs=question, outputs=[output, citations])
        
        gr.Markdown(
            """
            ---
            πŸ’‘ **Tip:** Questions are answered using relevant papers from the ArXiv dataset.
            """
        )

    demo.launch()


if __name__ == "__main__":
    run_gradio()