harshithasudhakar commited on
Commit
65bd869
·
verified ·
1 Parent(s): f311d71

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from transformers import pipeline
3
+ import streamlit as st
4
+ import fitz # PyMuPDF for PDF text extraction
5
+
6
+ # Load pretrained model for simplification
7
+ simplifier = pipeline("summarization", model="facebook/bart-large-cnn")
8
+
9
+ def simplify_text(text):
10
+ """Simplifies a given academic text using a pretrained model."""
11
+ simplified = simplifier(text, max_length=96, min_length=30, do_sample=False)
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
21
+ st.title("Text Simplification with Pretrained Model")
22
+ option = st.radio("Choose input type:", ("Text Input", "Upload PDF"))
23
+
24
+ if option == "Text Input":
25
+ user_text = st.text_area("Enter your text:")
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")