File size: 1,443 Bytes
65bd869
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import torch
from transformers import pipeline
import streamlit as st
import fitz  # PyMuPDF for PDF text extraction

# Load pretrained model for simplification
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

# Streamlit UI
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])  # Limit text length for processing
        st.subheader("Simplified Text:")
        st.write(simplified_text)

st.write("\nMade with ❤️ using Pretrained Models")