PDF_Translate / app.py
MUSCAT41's picture
Update app.py
c48c82a
raw
history blame
892 Bytes
import gradio as gr
from PyPDF2 import PdfReader
from textblob import TextBlob
def extract_text_from_pdf(file_path):
pdf = PdfReader(file_path)
text = ''
for page in pdf.pages:
text += page.extract_text()
return text
def translate_text(text, dest_lang='en'):
blob = TextBlob(text)
translation = blob.translate(to=dest_lang)
return str(translation)
def translate_pdf(file):
text = extract_text_from_pdf(file.name)
translation = translate_text(text)
return translation
iface = gr.Interface(fn=translate_pdf,
inputs=gr.inputs.File(label="Upload PDF file to translate"),
outputs='text',
title="PDF Translation App",
description="Use this application to translate from foreign language to English. Push 'Run' button when ready to translate.")
iface.launch()