MLDeveloper commited on
Commit
14c258c
Β·
verified Β·
1 Parent(s): a574ede

Upload app.py

Browse files
Files changed (1) hide show
  1. 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)}")