sathvikk commited on
Commit
edcfa46
Β·
verified Β·
1 Parent(s): 1c4d53d

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +24 -21
src/streamlit_app.py CHANGED
@@ -5,14 +5,17 @@ import streamlit as st
5
  import fitz # PyMuPDF
6
  from transformers import pipeline
7
 
8
- # Set page config
9
- st.set_page_config(page_title="PrepPal", page_icon="πŸ“˜", layout="wide")
10
 
11
- # Load summarizer model
12
- @st.cache_resource
13
- def load_summarizer():
14
- return pipeline("summarization", model="Falconsai/text_summarization")
15
 
 
 
 
 
16
 
17
  # Extract text from uploaded PDF
18
  def extract_text_from_pdf(uploaded_file):
@@ -22,7 +25,7 @@ def extract_text_from_pdf(uploaded_file):
22
  for page in doc:
23
  text += page.get_text()
24
  except Exception as e:
25
- st.error(f"❌ Error extracting text from PDF: {e}")
26
  return text
27
 
28
  # Summarize large text
@@ -34,38 +37,38 @@ def summarize_text(text, summarizer, max_chunk_length=2000):
34
  summary += result[0]['summary_text'] + "\n"
35
  return summary.strip()
36
 
37
- # Load model
38
- summarizer = load_summarizer()
39
-
40
- # UI
41
  tab1, tab2, tab3 = st.tabs(["πŸ“„ Summarize Notes", "❓ Ask a Doubt", "πŸ’¬ Feedback"])
42
 
 
43
  with tab1:
44
- st.header("πŸ“„ Upload Notes & Get Summary")
45
- st.write("Upload your class notes in PDF format to receive a summarized version.")
46
  uploaded_pdf = st.file_uploader("Upload your PDF notes (PDF only)", type=["pdf"])
47
 
48
  if uploaded_pdf:
49
- with st.spinner("Extracting text from PDF..."):
50
  pdf_text = extract_text_from_pdf(uploaded_pdf)
51
 
52
  if pdf_text.strip():
53
- st.subheader("πŸ“˜ Extracted Text (Preview)")
54
- st.text_area("Raw Text", pdf_text[:1000] + "...", height=200)
 
55
 
56
- if st.button("βœ‚οΈ Summarize"):
57
- with st.spinner("Summarizing... Please wait."):
 
58
  summary = summarize_text(pdf_text, summarizer)
59
- st.subheader("βœ… Summary")
60
  st.text_area("Summary Output", summary, height=300)
61
  st.download_button("⬇️ Download Summary", summary, file_name="summary.txt")
62
  else:
63
  st.warning("⚠️ No text found in the uploaded PDF.")
64
 
 
65
  with tab2:
66
  st.header("❓ Ask a Doubt")
67
- st.info("πŸ”§ This feature is under development. You’ll soon be able to chat with your notes using AI!")
68
 
 
69
  with tab3:
70
  st.header("πŸ’¬ User Feedback")
71
- st.info("πŸ“¬ A feedback form will be added here to collect your thoughts and improve PrepPal.")
 
5
  import fitz # PyMuPDF
6
  from transformers import pipeline
7
 
8
+ # Page configuration
9
+ st.set_page_config(page_title="StudyGenie πŸ“˜", layout="centered")
10
 
11
+ # Title
12
+ st.title("πŸ“„ StudyGenie - Summarize Your Notes")
13
+ st.write("Upload your PDF notes below and get a smart AI-generated summary instantly.")
 
14
 
15
+ # Load model only when needed
16
+ @st.cache_resource(show_spinner=False)
17
+ def load_summarizer():
18
+ return pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
19
 
20
  # Extract text from uploaded PDF
21
  def extract_text_from_pdf(uploaded_file):
 
25
  for page in doc:
26
  text += page.get_text()
27
  except Exception as e:
28
+ st.error(f"❌ Error reading PDF: {e}")
29
  return text
30
 
31
  # Summarize large text
 
37
  summary += result[0]['summary_text'] + "\n"
38
  return summary.strip()
39
 
40
+ # Tabs for multiple functions
 
 
 
41
  tab1, tab2, tab3 = st.tabs(["πŸ“„ Summarize Notes", "❓ Ask a Doubt", "πŸ’¬ Feedback"])
42
 
43
+ # Tab 1: Summarize
44
  with tab1:
 
 
45
  uploaded_pdf = st.file_uploader("Upload your PDF notes (PDF only)", type=["pdf"])
46
 
47
  if uploaded_pdf:
48
+ with st.spinner("πŸ” Extracting text from your PDF..."):
49
  pdf_text = extract_text_from_pdf(uploaded_pdf)
50
 
51
  if pdf_text.strip():
52
+ st.success("βœ… Text extracted successfully!")
53
+ st.subheader("πŸ”Ή Preview of Extracted Text")
54
+ st.text_area("Extracted Text", pdf_text[:1000] + "...", height=200)
55
 
56
+ if st.button("βœ‚οΈ Summarize Notes"):
57
+ with st.spinner("🧠 Summarizing..."):
58
+ summarizer = load_summarizer()
59
  summary = summarize_text(pdf_text, summarizer)
60
+ st.subheader("πŸ“˜ Summary")
61
  st.text_area("Summary Output", summary, height=300)
62
  st.download_button("⬇️ Download Summary", summary, file_name="summary.txt")
63
  else:
64
  st.warning("⚠️ No text found in the uploaded PDF.")
65
 
66
+ # Tab 2: Ask a Doubt
67
  with tab2:
68
  st.header("❓ Ask a Doubt")
69
+ st.info("πŸ”§ This feature is coming soon! You’ll be able to chat with your notes using AI.")
70
 
71
+ # Tab 3: Feedback
72
  with tab3:
73
  st.header("πŸ’¬ User Feedback")
74
+ st.info("πŸ“¬ A feedback form will be added here to help us improve StudyGenie.")