Download app.py from AI-Driven-Data-Driven/Arabic-Rag-Chatbot: direct link, hf CLI and curl.
- Browser
- Download file 2.24 kB
-
https://huggingface.co/spaces/AI-Driven-Data-Driven/Arabic-Rag-Chatbot/resolve/main/app.py
- Command line
-
hf download hf://spaces/AI-Driven-Data-Driven/Arabic-Rag-Chatbot/app.py
-
curl -L -o app.py https://huggingface.co/spaces/AI-Driven-Data-Driven/Arabic-Rag-Chatbot/resolve/main/app.py
2.24 kB
| 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) | |
| # --------------------------------------------------------- | |
| 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 | |
| ) | |