Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pdf-rag-app/.vs/VSWorkspaceState.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"ExpandedNodes": [
""
],
"PreviewInSolutionExplorer": false
}
Binary file not shown.
Binary file added pdf-rag-app/.vs/pdf-rag-app.slnx/v18/.wsuo
Binary file not shown.
12 changes: 12 additions & 0 deletions pdf-rag-app/.vs/pdf-rag-app.slnx/v18/DocumentLayout.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Version": 1,
"WorkspaceRootPath": "C:\\Users\\anand\\endee\\pdf-rag-app\\",
"Documents": [],
"DocumentGroupContainers": [
{
"Orientation": 0,
"VerticalTabListWidth": 256,
"DocumentGroups": []
}
]
}
Binary file added pdf-rag-app/.vs/slnx.sqlite
Binary file not shown.
Binary file added pdf-rag-app/__pycache__/main.cpython-313.pyc
Binary file not shown.
54 changes: 54 additions & 0 deletions pdf-rag-app/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from fastapi import FastAPI, UploadFile
import shutil
import os

# Gemini
import google.generativeai as genai

# PDF Reader
from pypdf import PdfReader

# Load API key
from dotenv import load_dotenv
load_dotenv()

genai.configure(api_key=os.getenv("GEMINI_API_KEY"))
model = genai.GenerativeModel("gemini-pro")

app = FastAPI()

# simple memory storage
PDF_TEXT = ""

@app.post("/upload/")
async def upload_pdf(file: UploadFile):
global PDF_TEXT

with open(file.filename, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)

reader = PdfReader(file.filename)
text = ""

for page in reader.pages:
text += page.extract_text()

PDF_TEXT = text

return {"message": "PDF uploaded and processed"}

@app.get("/ask/")
def ask_question(query: str):
global PDF_TEXT

prompt = f"""
Answer the question based on this PDF content:

{PDF_TEXT[:3000]}

Question: {query}
"""

response = model.generate_content(prompt)

return {"answer": response.text}
Empty file added pdf-rag-app/python
Empty file.