Fidamohammad commited on
Commit
e1eff6f
·
verified ·
1 Parent(s): 0cb2f63

Upload 3 files

Browse files
Files changed (3) hide show
  1. main.py +17 -0
  2. requirements.txt +5 -0
  3. research_pipeline.py +36 -0
main.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from fastapi import FastAPI, Request, Form
3
+ from fastapi.responses import FileResponse, HTMLResponse
4
+ from fastapi.templating import Jinja2Templates
5
+ from research_pipeline import generate_research_report
6
+
7
+ app = FastAPI()
8
+ templates = Jinja2Templates(directory="templates")
9
+
10
+ @app.get("/", response_class=HTMLResponse)
11
+ async def homepage(request: Request):
12
+ return templates.TemplateResponse("index.html", {"request": request})
13
+
14
+ @app.post("/generate", response_class=FileResponse)
15
+ async def generate(topic: str = Form(...)):
16
+ pdf_path = generate_research_report(topic)
17
+ return FileResponse(pdf_path, media_type="application/pdf", filename="research_report.pdf")
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ jinja2
4
+ requests
5
+ fpdf
research_pipeline.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import requests
3
+ from fpdf import FPDF
4
+
5
+ URL = "https://api.semanticscholar.org/graph/v1/paper/search"
6
+
7
+ def search(topic, limit=5):
8
+ params = {"query": topic, "limit": limit, "fields": "title,abstract,year,authors,citationCount"}
9
+ r = requests.get(URL, params=params, timeout=20)
10
+ return r.json().get("data", [])
11
+
12
+ def create_pdf(topic, papers):
13
+ path = "research_report.pdf"
14
+ pdf = FPDF()
15
+ pdf.add_page()
16
+ pdf.set_auto_page_break(auto=True, margin=15)
17
+ pdf.add_font("DejaVu", "", fname="DejaVuSans.ttf", uni=True)
18
+ pdf.set_font("DejaVu", "", 14)
19
+ pdf.cell(0, 10, f"Research Report: {topic}", ln=True)
20
+ pdf.ln(5)
21
+ pdf.set_font("DejaVu", "", 11)
22
+ for i, p in enumerate(papers, 1):
23
+ pdf.multi_cell(0, 10, f"{i}. {p.get('title','No Title')}")
24
+ pdf.set_font("DejaVu", "", 10)
25
+ pdf.multi_cell(0, 6, f"Year: {p.get('year','N/A')}")
26
+ pdf.multi_cell(0, 6, f"Citations: {p.get('citationCount','N/A')}")
27
+ pdf.ln(2)
28
+ pdf.multi_cell(0, 6, "Abstract:
29
+ " + p.get("abstract","N/A"))
30
+ pdf.ln(5)
31
+ pdf.set_font("DejaVu", "", 11)
32
+ pdf.output(path)
33
+ return path
34
+
35
+ def generate_research_report(topic):
36
+ return create_pdf(topic, search(topic))