makdadTaleb's picture
Upload folder using huggingface_hub
4e7e4c0 verified
import sys
from pathlib import Path
ROOT_DIR = Path(__file__).resolve().parent.parent
if str(ROOT_DIR) not in sys.path:
sys.path.insert(0, str(ROOT_DIR))
import streamlit as st
import requests
API_URL = "http://0.0.0.0:8000/ask"
st.set_page_config(
page_title="Lecture RAG",
layout="wide",
)
st.title("๐Ÿ“š Lecture RAG Assistant")
if "messages" not in st.session_state:
st.session_state.messages = []
chat_container = st.container()
with chat_container:
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
question = st.chat_input("ุงูƒุชุจ ุณุคุงู„ูƒ ู‡ู†ุง / Ask your question")
if question:
st.session_state.messages.append({"role": "user", "content": question})
with chat_container:
with st.chat_message("user"):
st.markdown(question)
with st.chat_message("assistant"):
with st.spinner("Thinking..."):
try:
response = requests.post(
API_URL,
json={"question": question},
timeout=120
)
response.raise_for_status()
data = response.json()
answer = data.get("answer", "No answer returned.")
except Exception as e:
data = {}
answer = f"โŒ API error: {e}"
st.markdown(answer)
if data.get("citations"):
with st.expander("๐Ÿ“Œ Sources"):
seen = set()
for c in data["citations"].values():
key = (c["source"], c["page"])
if key not in seen:
seen.add(key)
st.markdown(f"- ๐Ÿ“„ `{c['source']}` | page `{c['page']}`")
st.session_state.messages.append({"role": "assistant", "content": answer})