|
import torch |
|
from transformers import pipeline |
|
import streamlit as st |
|
import fitz |
|
|
|
|
|
simplifier = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
|
def simplify_text(text): |
|
"""Simplifies a given academic text using a pretrained model.""" |
|
simplified = simplifier(text, max_length=96, min_length=30, do_sample=False) |
|
return simplified[0]['summary_text'] |
|
|
|
def extract_text_from_pdf(pdf_file): |
|
"""Extracts text from an uploaded PDF file.""" |
|
doc = fitz.open(pdf_file) |
|
text = "\n".join(page.get_text("text") for page in doc) |
|
return text |
|
|
|
|
|
st.title("Text Simplification with Pretrained Model") |
|
option = st.radio("Choose input type:", ("Text Input", "Upload PDF")) |
|
|
|
if option == "Text Input": |
|
user_text = st.text_area("Enter your text:") |
|
if st.button("Simplify") and user_text: |
|
simplified_text = simplify_text(user_text) |
|
st.subheader("Simplified Text:") |
|
st.write(simplified_text) |
|
|
|
elif option == "Upload PDF": |
|
uploaded_file = st.file_uploader("Upload a PDF", type=["pdf"]) |
|
if uploaded_file: |
|
extracted_text = extract_text_from_pdf(uploaded_file) |
|
simplified_text = simplify_text(extracted_text[:1000]) |
|
st.subheader("Simplified Text:") |
|
st.write(simplified_text) |
|
|
|
st.write("\nMade with ❤️ using Pretrained Models") |
|
|