Sazzz02 commited on
Commit
4f87cd7
Β·
verified Β·
1 Parent(s): 9d075c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -44
app.py CHANGED
@@ -1,7 +1,3 @@
1
- # app.py
2
- # Note: Hugging Face Spaces automatically looks for app.py or main.py
3
- # The content from all your files is combined here for easy deployment.
4
-
5
  import streamlit as st
6
  import os
7
  import PyPDF2
@@ -18,18 +14,7 @@ import plotly.express as px
18
  import pandas as pd
19
  from datetime import datetime
20
 
21
- # --- Dependencies for Hugging Face (will be in requirements.txt) ---
22
- # streamlit
23
- # PyPDF2
24
- # docx
25
- # langchain
26
- # langchain-openai
27
- # langchain-community
28
- # groq
29
- # plotly
30
- # pandas
31
- # python-dotenv (not strictly necessary with HF secrets, but good practice)
32
- # -------------------------------------------------------------------
33
 
34
  class DocumentProcessor:
35
  def __init__(self):
@@ -536,30 +521,26 @@ class LearningDashboard:
536
  # Streamlit App Pages (Combined)
537
 
538
  def upload_and_process_page(doc_processor):
539
- st.header("πŸ“‚ Upload Your Learning Material")
540
- uploaded_file = st.file_uploader(
541
- "Choose a file",
542
- type=['pdf', 'docx'],
543
- help="Upload PDF or Word documents"
544
- )
545
- if uploaded_file is not None:
546
- file_path = f"/tmp/{uploaded_file.name}"
547
- with open(file_path, "wb") as f:
548
- f.write(uploaded_file.getbuffer())
549
- st.success(f"File uploaded: {uploaded_file.name}")
550
- if st.button("Process Document"):
551
- with st.spinner("Processing document..."):
552
- try:
553
- file_extension = uploaded_file.name.split('.')[-1]
554
- vectorstore, chunk_count = doc_processor.process_document(
555
- file_path, file_extension
556
- )
557
- st.session_state.vectorstore = vectorstore
558
- st.session_state.document_name = uploaded_file.name
559
- st.success(f"Document processed successfully! Created {chunk_count} text chunks.")
560
- st.info("You can now go to 'Learn Topic' to start learning!")
561
- except Exception as e:
562
- st.error(f"Error processing document: {str(e)}")
563
 
564
  def learn_topic_page(rag_system):
565
  st.header("πŸ“– Learn About Any Topic")
@@ -619,20 +600,20 @@ def main():
619
 
620
  st.sidebar.title("Navigation")
621
  page = st.sidebar.selectbox("Choose a page:",
622
- ["Upload & Process", "Learn Topic", "Play Games", "Dashboard"])
623
 
624
- if page == "Upload & Process":
625
  upload_and_process_page(doc_processor)
626
  elif page == "Learn Topic":
627
  if 'vectorstore' in st.session_state:
628
  learn_topic_page(RAGLearningSystem(st.session_state.vectorstore))
629
  else:
630
- st.warning("Please upload and process a document first!")
631
  elif page == "Play Games":
632
  if 'vectorstore' in st.session_state:
633
  play_games_page(RAGLearningSystem(st.session_state.vectorstore), games)
634
  else:
635
- st.warning("Please upload and process a document first!")
636
  elif page == "Dashboard":
637
  dashboard.show_dashboard()
638
 
 
 
 
 
 
1
  import streamlit as st
2
  import os
3
  import PyPDF2
 
14
  import pandas as pd
15
  from datetime import datetime
16
 
17
+ # Class Definitions (Combined)
 
 
 
 
 
 
 
 
 
 
 
18
 
19
  class DocumentProcessor:
20
  def __init__(self):
 
521
  # Streamlit App Pages (Combined)
522
 
523
  def upload_and_process_page(doc_processor):
524
+ st.header("πŸ“‚ Process Your Learning Material")
525
+
526
+ # Hardcoded file name and path
527
+ file_path = "ragdatascience.pdf"
528
+ file_extension = "pdf"
529
+
530
+ st.info(f"Processing the pre-uploaded file: `{file_path}`")
531
+
532
+ if st.button("Process Document"):
533
+ with st.spinner("Processing document..."):
534
+ try:
535
+ vectorstore, chunk_count = doc_processor.process_document(
536
+ file_path, file_extension
537
+ )
538
+ st.session_state.vectorstore = vectorstore
539
+ st.session_state.document_name = file_path
540
+ st.success(f"Document processed successfully! Created {chunk_count} text chunks.")
541
+ st.info("You can now go to 'Learn Topic' to start learning!")
542
+ except Exception as e:
543
+ st.error(f"Error processing document: {str(e)}")
 
 
 
 
544
 
545
  def learn_topic_page(rag_system):
546
  st.header("πŸ“– Learn About Any Topic")
 
600
 
601
  st.sidebar.title("Navigation")
602
  page = st.sidebar.selectbox("Choose a page:",
603
+ ["Process Document", "Learn Topic", "Play Games", "Dashboard"])
604
 
605
+ if page == "Process Document":
606
  upload_and_process_page(doc_processor)
607
  elif page == "Learn Topic":
608
  if 'vectorstore' in st.session_state:
609
  learn_topic_page(RAGLearningSystem(st.session_state.vectorstore))
610
  else:
611
+ st.warning("Please process a document first!")
612
  elif page == "Play Games":
613
  if 'vectorstore' in st.session_state:
614
  play_games_page(RAGLearningSystem(st.session_state.vectorstore), games)
615
  else:
616
+ st.warning("Please process a document first!")
617
  elif page == "Dashboard":
618
  dashboard.show_dashboard()
619