-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
98 lines (80 loc) · 3.22 KB
/
Copy pathapp.py
File metadata and controls
98 lines (80 loc) · 3.22 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
PaperLens — Gradio UI
Run: python app.py
"""
import os
import gradio as gr
from pipeline import PaperLensPipeline
GROQ_API_KEY = os.environ.get("GROQ_API_KEY", "")
if not GROQ_API_KEY:
raise EnvironmentError(
"GROQ_API_KEY not set. Export it: export GROQ_API_KEY=your_key"
)
pipeline = PaperLensPipeline(groq_api_key=GROQ_API_KEY)
def upload_and_process(pdf_file):
if pdf_file is None:
return "❌ Please upload a PDF file."
try:
text = pipeline.load_pdf(pdf_file.name)
chunks = pipeline.chunk_text(text)
pipeline.build_index(chunks)
return pipeline.summarize()
except Exception as e:
return f"❌ Error processing PDF: {e}"
def answer_question(question: str):
if not question.strip():
return "❌ Please enter a question."
if pipeline.index is None:
return "❌ Please upload a paper first."
try:
return pipeline.answer(question)
except Exception as e:
return f"❌ Error: {e}"
def run_task(task_fn):
if pipeline.index is None:
return "❌ Please upload a paper first."
try:
return task_fn()
except Exception as e:
return f"❌ Error: {e}"
with gr.Blocks(title="PaperLens — Research Paper Intelligence",
theme=gr.themes.Soft()) as demo:
gr.Markdown("""
# 🔍 PaperLens — AI Research Paper Intelligence
Upload any research paper PDF → get instant summaries, Q&A, interview prep,
implementation roadmaps, and critical analysis powered by RAG + LLaMA 3.1.
""")
with gr.Tab("📄 Upload & Summarize"):
pdf_input = gr.File(label="Upload Research Paper (PDF)",
file_types=[".pdf"])
upload_btn = gr.Button("Analyze Paper", variant="primary")
summary_output = gr.Markdown(label="Paper Summary")
upload_btn.click(upload_and_process, pdf_input, summary_output)
with gr.Tab("💬 Ask Questions"):
question_input = gr.Textbox(
label="Ask anything about the paper",
placeholder="e.g. What evaluation metrics did they use?"
)
ask_btn = gr.Button("Ask")
answer_output = gr.Markdown(label="Answer")
ask_btn.click(answer_question, question_input, answer_output)
with gr.Tab("🎯 Interview Prep"):
interview_btn = gr.Button("Generate Interview Questions", variant="primary")
interview_output = gr.Markdown(label="Interview Q&A")
interview_btn.click(
lambda: run_task(pipeline.interview_prep), None, interview_output
)
with gr.Tab("🗺️ Implementation Roadmap"):
roadmap_btn = gr.Button("Generate Implementation Roadmap", variant="primary")
roadmap_output = gr.Markdown(label="How to implement this paper")
roadmap_btn.click(
lambda: run_task(pipeline.implementation_roadmap), None, roadmap_output
)
with gr.Tab("🔬 Critical Analysis"):
critique_btn = gr.Button("Analyze Strengths & Weaknesses", variant="primary")
critique_output = gr.Markdown(label="Critical Analysis")
critique_btn.click(
lambda: run_task(pipeline.critical_analysis), None, critique_output
)
if __name__ == "__main__":
demo.launch()