harshithasudhakar commited on
Commit
b9d50d4
·
verified ·
1 Parent(s): 2917eb1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -7
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
- doc = fitz.open(pdf_file)
17
- text = "\n".join(page.get_text("text") for page in doc)
 
 
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.write(simplified_text)
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
- simplified_text = simplify_text(extracted_text[:1000]) # Limit text length for processing
36
- st.subheader("Simplified Text:")
37
- st.write(simplified_text)
 
 
 
 
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")