Ahmed-Alghamdi's picture
Update app.py
6130cb8 verified
import streamlit as st
from main import initialize_system, process_query
# ---------------------------------------------------------
# Streamlit page configuration
# ---------------------------------------------------------
st.set_page_config(
page_title="Arabic RAG Chatbot 🤖",
page_icon="🤖",
layout="wide",
)
# ---------------------------------------------------------
# Title and description
# ---------------------------------------------------------
st.title("🤖 Arabic RAG Chatbot")
st.markdown("""
مرحبًا! 👋
""")
# ---------------------------------------------------------
# Cached system initialization (so it doesn't reload every time)
# ---------------------------------------------------------
@st.cache_resource
def load_rag_system():
search_engine, response_generator = initialize_system()
return search_engine, response_generator
search_engine, response_generator = load_rag_system()
# ---------------------------------------------------------
# Input section
# ---------------------------------------------------------
st.divider()
query = st.text_input("📝 أدخل سؤالك هنا:", placeholder="مثال: ما هي نسبة الحضور المطلوبة؟")
# ---------------------------------------------------------
# Query handling
# ---------------------------------------------------------
if st.button("بحث") or query:
if not query.strip():
st.warning("يرجى كتابة سؤال أولاً.")
else:
with st.spinner("⏳ جارٍ البحث عن الإجابة..."):
try:
response = process_query(query, search_engine, response_generator)
if response:
st.success("💬 الإجابة:")
st.write(response)
else:
st.info("لم يتم العثور على إجابة ذات صلة في المستندات.")
except Exception as e:
st.error(f"حدث خطأ أثناء توليد الإجابة: {e}")
# ---------------------------------------------------------
# Footer
# ---------------------------------------------------------
st.divider()
st.markdown(" ",
unsafe_allow_html=True
)