Spaces:
Build error
Build error
File size: 2,381 Bytes
14c258c |
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 |
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)}")
|