Spaces:
Build error
Build error
| import streamlit as st | |
| import requests | |
| st.set_page_config(page_title="AI Tutor", layout="wide") | |
| st.title("π§ Agentic AI Tutor & Quiz App") | |
| with st.sidebar: | |
| st.header("βοΈ Configuration") | |
| backend_url = st.text_input("Backend URL", "http://127.0.0.1:8000", help="Backend server address") | |
| st.info("β Backend must be running on this URL") | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| subject = st.selectbox("π Subject", ["Physics", "Maths", "Biology", "Chemistry"]) | |
| level = st.selectbox("π Level", ["Beginner", "Intermediate", "Advanced"]) | |
| with col2: | |
| mode = st.radio("π― Mode", ["tutor", "quiz"], horizontal=True) | |
| st.info("**Tutor** for explanations, **Quiz** for assessments") | |
| question = "" | |
| if mode == "tutor": | |
| question = st.text_area("β Ask your question", placeholder="Enter your question here...") | |
| else: | |
| st.info("π Quiz mode will generate assessment questions") | |
| if st.button("π Run Agent", use_container_width=True, type="primary"): | |
| if mode == "tutor" and not question.strip(): | |
| st.warning("β οΈ Please enter a question for tutor mode") | |
| else: | |
| with st.spinner("β³ Processing your request..."): | |
| try: | |
| payload = { | |
| "subject": subject, | |
| "level": level, | |
| "question": question if mode == "tutor" else "", | |
| "mode": mode | |
| } | |
| response = requests.post( | |
| f"{backend_url}/agent", | |
| json=payload, | |
| timeout=30 | |
| ) | |
| if response.status_code == 200: | |
| result = response.json().get("result", "No response") | |
| st.success("β Response received!") | |
| st.markdown("---") | |
| st.write(result) | |
| st.markdown("---") | |
| else: | |
| st.error(f"β Server error: {response.status_code}") | |
| except requests.exceptions.ConnectionError: | |
| st.error(f"β Cannot connect to backend at {backend_url}") | |
| st.info("Start backend with: `python backend/main.py`") | |
| except Exception as e: | |
| st.error(f"β Error: {str(e)}") | |