File size: 2,237 Bytes
6b0b18e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6130cb8
6b0b18e
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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
)