Spaces:
Sleeping
Sleeping
| 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) | |
| 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}") |