Spaces:
Build error
Build error
Upload app.py
Browse files- app.py/app.py +60 -0
app.py/app.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
st.set_page_config(page_title="AI Tutor", layout="wide")
|
| 5 |
+
st.title("π§ Agentic AI Tutor & Quiz App")
|
| 6 |
+
|
| 7 |
+
with st.sidebar:
|
| 8 |
+
st.header("βοΈ Configuration")
|
| 9 |
+
backend_url = st.text_input("Backend URL", "http://127.0.0.1:8000", help="Backend server address")
|
| 10 |
+
st.info("β Backend must be running on this URL")
|
| 11 |
+
|
| 12 |
+
col1, col2 = st.columns(2)
|
| 13 |
+
|
| 14 |
+
with col1:
|
| 15 |
+
subject = st.selectbox("π Subject", ["Physics", "Maths", "Biology", "Chemistry"])
|
| 16 |
+
level = st.selectbox("π Level", ["Beginner", "Intermediate", "Advanced"])
|
| 17 |
+
|
| 18 |
+
with col2:
|
| 19 |
+
mode = st.radio("π― Mode", ["tutor", "quiz"], horizontal=True)
|
| 20 |
+
st.info("**Tutor** for explanations, **Quiz** for assessments")
|
| 21 |
+
|
| 22 |
+
question = ""
|
| 23 |
+
if mode == "tutor":
|
| 24 |
+
question = st.text_area("β Ask your question", placeholder="Enter your question here...")
|
| 25 |
+
else:
|
| 26 |
+
st.info("π Quiz mode will generate assessment questions")
|
| 27 |
+
|
| 28 |
+
if st.button("π Run Agent", use_container_width=True, type="primary"):
|
| 29 |
+
if mode == "tutor" and not question.strip():
|
| 30 |
+
st.warning("β οΈ Please enter a question for tutor mode")
|
| 31 |
+
else:
|
| 32 |
+
with st.spinner("β³ Processing your request..."):
|
| 33 |
+
try:
|
| 34 |
+
payload = {
|
| 35 |
+
"subject": subject,
|
| 36 |
+
"level": level,
|
| 37 |
+
"question": question if mode == "tutor" else "",
|
| 38 |
+
"mode": mode
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
response = requests.post(
|
| 42 |
+
f"{backend_url}/agent",
|
| 43 |
+
json=payload,
|
| 44 |
+
timeout=30
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if response.status_code == 200:
|
| 48 |
+
result = response.json().get("result", "No response")
|
| 49 |
+
st.success("β
Response received!")
|
| 50 |
+
st.markdown("---")
|
| 51 |
+
st.write(result)
|
| 52 |
+
st.markdown("---")
|
| 53 |
+
else:
|
| 54 |
+
st.error(f"β Server error: {response.status_code}")
|
| 55 |
+
|
| 56 |
+
except requests.exceptions.ConnectionError:
|
| 57 |
+
st.error(f"β Cannot connect to backend at {backend_url}")
|
| 58 |
+
st.info("Start backend with: `python backend/main.py`")
|
| 59 |
+
except Exception as e:
|
| 60 |
+
st.error(f"β Error: {str(e)}")
|