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)}")