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