-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrontend.py
More file actions
71 lines (58 loc) · 2.55 KB
/
frontend.py
File metadata and controls
71 lines (58 loc) · 2.55 KB
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
62
63
64
65
66
67
68
69
70
71
import streamlit as st
import requests
import io
# ---------- CONFIG ----------
BACKEND_URL = "https://class-report-test-backend-3.onrender.com/process_class" # 🔹 replace with your actual Render URL
st.set_page_config(page_title="Classroom Audio Monitor", page_icon="🎙️", layout="centered")
st.title("🎙️ Classroom Audio Monitoring System")
st.markdown("""
Upload or record classroom audio and automatically generate:
- Full transcript
- Summary report
- Email delivery
""")
# ---------- FORM ----------
with st.form("class_form"):
teacher_name = st.text_input("Teacher Name")
subject = st.text_input("Subject")
grade = st.text_input("Class")
section = st.text_input("Section")
period_number = st.text_input("Period Number")
start_time = st.text_input("Start Time")
email = st.text_input("Email to receive report")
st.markdown("#### Audio Input")
record_option = st.radio("Choose Input Method", ["🎤 Record Audio", "📁 Upload Audio"])
audio_data = None
if record_option == "🎤 Record Audio":
audio_data = st.audio_input("Record your class audio") # Streamlit's recorder
else:
audio_data = st.file_uploader("Upload a .wav or .mp3 file", type=["wav", "mp3"])
submitted = st.form_submit_button("🚀 Generate Report")
# ---------- SUBMIT ----------
if submitted:
if not audio_data:
st.error("Please provide an audio file before submitting.")
else:
with st.spinner("Uploading and processing audio... ⏳"):
files = {"audio_file": audio_data}
data = {
"teacher_name": teacher_name,
"subject": subject,
"grade": grade,
"section": section,
"period_number": period_number,
"start_time": start_time,
"email": email
}
try:
response = requests.post(BACKEND_URL, data=data, files=files, timeout=600)
if response.status_code == 200:
result = response.json()
if result["status"] == "success":
st.success("✅ Report generated and emailed successfully!")
else:
st.error(f"⚠️ Error: {result.get('message', 'Unknown error')}")
else:
st.error(f"❌ Failed! Status code: {response.status_code}")
except Exception as e:
st.error(f"Error connecting to backend: {e}")