Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,11 @@ def simplify_text(text):
|
|
| 12 |
return simplified[0]['summary_text']
|
| 13 |
|
| 14 |
def extract_text_from_pdf(pdf_file):
|
| 15 |
-
"""Extracts text from an uploaded PDF file."""
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
| 18 |
return text
|
| 19 |
|
| 20 |
# Streamlit UI
|
|
@@ -26,14 +28,18 @@ if option == "Text Input":
|
|
| 26 |
if st.button("Simplify") and user_text:
|
| 27 |
simplified_text = simplify_text(user_text)
|
| 28 |
st.subheader("Simplified Text:")
|
| 29 |
-
st.
|
| 30 |
|
| 31 |
elif option == "Upload PDF":
|
| 32 |
uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])
|
| 33 |
if uploaded_file:
|
| 34 |
extracted_text = extract_text_from_pdf(uploaded_file)
|
| 35 |
-
|
| 36 |
-
st.
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
st.write("\nMade with ❤️ using Pretrained Models")
|
|
|
|
| 12 |
return simplified[0]['summary_text']
|
| 13 |
|
| 14 |
def extract_text_from_pdf(pdf_file):
|
| 15 |
+
"""Extracts text from an uploaded PDF file stream."""
|
| 16 |
+
text = ""
|
| 17 |
+
with fitz.open(stream=pdf_file.read(), filetype="pdf") as doc:
|
| 18 |
+
for page in doc:
|
| 19 |
+
text += page.get_text()
|
| 20 |
return text
|
| 21 |
|
| 22 |
# Streamlit UI
|
|
|
|
| 28 |
if st.button("Simplify") and user_text:
|
| 29 |
simplified_text = simplify_text(user_text)
|
| 30 |
st.subheader("Simplified Text:")
|
| 31 |
+
st.text_area("Simplified Output", simplified_text, height=150)
|
| 32 |
|
| 33 |
elif option == "Upload PDF":
|
| 34 |
uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"])
|
| 35 |
if uploaded_file:
|
| 36 |
extracted_text = extract_text_from_pdf(uploaded_file)
|
| 37 |
+
st.subheader("Extracted Text from PDF:")
|
| 38 |
+
st.text_area("Extracted Text", extracted_text, height=200)
|
| 39 |
+
|
| 40 |
+
if st.button("Simplify Extracted Text"):
|
| 41 |
+
simplified_text = simplify_text(extracted_text[:1000]) # Limit length for model input
|
| 42 |
+
st.subheader("Simplified Text:")
|
| 43 |
+
st.text_area("Simplified Output", simplified_text, height=150)
|
| 44 |
|
| 45 |
st.write("\nMade with ❤️ using Pretrained Models")
|