Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import re
|
| 3 |
+
from io import BytesIO
|
| 4 |
+
import PyPDF2
|
| 5 |
+
import docx2txt
|
| 6 |
+
|
| 7 |
+
st.set_page_config(page_title="π Note Input", layout="centered")
|
| 8 |
+
st.title("π Type of Text Input")
|
| 9 |
+
|
| 10 |
+
def extract_pdf_text(uploaded_file):
|
| 11 |
+
pdf_reader = PyPDF2.PdfReader(uploaded_file)
|
| 12 |
+
text = ""
|
| 13 |
+
for page in pdf_reader.pages:
|
| 14 |
+
page_text = page.extract_text()
|
| 15 |
+
if page_text:
|
| 16 |
+
text += page_text + "\n"
|
| 17 |
+
return text
|
| 18 |
+
|
| 19 |
+
def extract_docx_text(uploaded_file):
|
| 20 |
+
# docx2txt.process accepts a path or a file-like object
|
| 21 |
+
return docx2txt.process(uploaded_file)
|
| 22 |
+
|
| 23 |
+
input_type = st.selectbox(
|
| 24 |
+
"Select the type of input:",
|
| 25 |
+
["Select...", "PDF", "Word Document", "Text"]
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
if input_type == "PDF":
|
| 29 |
+
uploaded_file = st.file_uploader("Upload a PDF file", type=["pdf"])
|
| 30 |
+
if uploaded_file is not None:
|
| 31 |
+
extracted_text = extract_pdf_text(uploaded_file)
|
| 32 |
+
st.subheader("π Extracted PDF Text")
|
| 33 |
+
st.text_area("Content", extracted_text, height=300)
|
| 34 |
+
|
| 35 |
+
elif input_type == "Word Document":
|
| 36 |
+
uploaded_file = st.file_uploader("Upload a DOCX file", type=["docx"])
|
| 37 |
+
if uploaded_file is not None:
|
| 38 |
+
extracted_text = extract_docx_text(uploaded_file)
|
| 39 |
+
st.subheader("π Extracted DOCX Text")
|
| 40 |
+
st.text_area("Content", extracted_text, height=300)
|
| 41 |
+
|
| 42 |
+
elif input_type == "Text":
|
| 43 |
+
notes = st.text_area(
|
| 44 |
+
"Paste your class notes here",
|
| 45 |
+
height=300,
|
| 46 |
+
placeholder="e.g., AI notes ..."
|
| 47 |
+
)
|
| 48 |
+
if notes:
|
| 49 |
+
st.subheader("π Your Input Text")
|
| 50 |
+
st.text_area("Content", notes, height=300)
|
| 51 |
+
|
| 52 |
+
else:
|
| 53 |
+
st.info("Please select an input type to get started.")
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
|