Update app.py
Browse files
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 |
-
#
|
| 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("π
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
|
| 546 |
-
|
| 547 |
-
|
| 548 |
-
|
| 549 |
-
|
| 550 |
-
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
|
| 554 |
-
|
| 555 |
-
|
| 556 |
-
|
| 557 |
-
|
| 558 |
-
|
| 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 |
-
["
|
| 623 |
|
| 624 |
-
if page == "
|
| 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
|
| 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
|
| 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 |
|