rag-pdf-chat / app.py
Mehriddin1997's picture
fix streamlit crash
e0db14c
import streamlit as st
import tempfile
import os
import sys
# πŸ”₯ import fix
sys.path.append(os.path.dirname(__file__))
from rag_system.rag_pipeline import RAGPipeline
st.set_page_config(page_title="RAG PDF Chat", layout="wide")
st.title("πŸ“„ RAG PDF Chat")
# πŸ”₯ RAG init (safe)
@st.cache_resource
def load_rag():
return RAGPipeline(persist_directory="/tmp/chroma")
try:
rag = load_rag()
except Exception as e:
st.error(f"RAG init error: {e}")
st.stop()
uploaded_file = st.file_uploader("πŸ“€ PDF yuklang", type=["pdf"])
if uploaded_file:
try:
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp:
tmp.write(uploaded_file.read())
temp_path = tmp.name
st.success("PDF yuklandi!")
rag.index_document(temp_path)
question = st.text_input("❓ Savol ber:")
if question:
answer = rag.query(question)
st.markdown("### πŸ€– Javob:")
st.write(answer)
except Exception as e:
st.error(f"Xatolik: {e}")