-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
90 lines (71 loc) · 2.62 KB
/
Copy pathapp.py
File metadata and controls
90 lines (71 loc) · 2.62 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import sys
import streamlit as st
# Don't create __pycache__ folders
sys.dont_write_bytecode = True
from pdf_utils import extract_text_from_pdf
from agent import generate_summary, generate_quiz
# -----------------------------
# Page config
# -----------------------------
st.set_page_config(page_title="Study Notes Agent", layout="wide")
st.title("📚 Study Notes Summarizer & Quiz Generator")
st.write("Upload a PDF, get a smart summary, then generate a quiz from it.")
# -----------------------------
# Session state (to remember data)
# -----------------------------
if "pdf_text" not in st.session_state:
st.session_state.pdf_text = None
if "summary" not in st.session_state:
st.session_state.summary = None
if "quiz" not in st.session_state:
st.session_state.quiz = None
# -----------------------------
# Level 1 — Upload PDF
# -----------------------------
uploaded_file = st.file_uploader("Upload your study PDF", type=["pdf"])
if uploaded_file is None:
st.info("Please upload a PDF to begin.")
st.stop()
st.success("✅ PDF uploaded successfully!")
# -----------------------------
# Level 2 — Extract text
# -----------------------------
with st.spinner("Extracting text from PDF..."):
pdf_text = extract_text_from_pdf(uploaded_file)
st.session_state.pdf_text = pdf_text
st.subheader("📄 Extracted Text Preview")
if isinstance(pdf_text, str) and len(pdf_text) > 1500:
st.write(pdf_text[:1500] + "...")
else:
st.write(pdf_text)
# -----------------------------
# Level 3 — Buttons (Summary + Quiz)
# -----------------------------
st.markdown("---")
st.subheader("⚙️ AI Actions")
col1, col2 = st.columns(2)
with col1:
if st.button("✨ Generate Summary", type="primary"):
if not st.session_state.pdf_text:
st.warning("No PDF text found. Please re-upload the file.")
else:
with st.spinner("Generating AI summary..."):
st.session_state.summary = generate_summary(st.session_state.pdf_text)
with col2:
if st.button("📝 Create Quiz"):
if not st.session_state.pdf_text:
st.warning("No PDF text found. Please re-upload the file.")
else:
with st.spinner("Generating quiz from the PDF..."):
st.session_state.quiz = generate_quiz(st.session_state.pdf_text)
# -----------------------------
# Level 4 — Show results
# -----------------------------
if st.session_state.summary:
st.markdown("---")
st.subheader("📚 AI Summary")
st.write(st.session_state.summary)
if st.session_state.quiz:
st.markdown("---")
st.subheader("🧪 Quiz Questions")
st.write(st.session_state.quiz)