-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
34 lines (26 loc) · 1.11 KB
/
app.py
File metadata and controls
34 lines (26 loc) · 1.11 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
import streamlit as st
import google.generativeai as genai
from utils.extract_text import extract_text_from_pdf
from utils.rag_qa_engine import rag_query
from config import GEMINI_API_KEY
import os
# Configure Gemini API
genai.configure(api_key=GEMINI_API_KEY)
st.set_page_config(page_title="📄 RAG with Gemini", layout="wide")
st.title("📄 RAG (Retrieval-Augmented Generation) with Gemini + Streamlit")
uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])
if uploaded_file:
file_path = os.path.join("data/uploads", uploaded_file.name)
with open(file_path, "wb") as f:
f.write(uploaded_file.getbuffer())
st.success("✅ File uploaded successfully!")
if st.button("Extract & Build Index"):
text = extract_text_from_pdf(file_path)
st.session_state["docs"] = text.split("\n")
st.success("✅ Text extracted and indexed!")
if "docs" in st.session_state:
user_query = st.text_input("Ask a question from the document:")
if user_query:
answer = rag_query(user_query, st.session_state["docs"])
st.write("### 🤖 Answer:")
st.write(answer)