MUSCAT41 commited on
Commit
c48c82a
1 Parent(s): bda8b79

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -1,15 +1,12 @@
1
  import gradio as gr
 
2
  from textblob import TextBlob
3
- import PyPDF2
4
 
5
  def extract_text_from_pdf(file_path):
6
- pdf_file_obj = open(file_path, 'rb')
7
- pdf_reader = PyPDF2.PdfFileReader(pdf_file_obj)
8
  text = ''
9
- for page_num in range(pdf_reader.numPages):
10
- page_obj = pdf_reader.getPage(page_num)
11
- text += page_obj.extractText()
12
- pdf_file_obj.close()
13
  return text
14
 
15
  def translate_text(text, dest_lang='en'):
@@ -22,5 +19,9 @@ def translate_pdf(file):
22
  translation = translate_text(text)
23
  return translation
24
 
25
- iface = gr.Interface(fn=translate_pdf, inputs='file', outputs='text')
 
 
 
 
26
  iface.launch()
 
1
  import gradio as gr
2
+ from PyPDF2 import PdfReader
3
  from textblob import TextBlob
 
4
 
5
  def extract_text_from_pdf(file_path):
6
+ pdf = PdfReader(file_path)
 
7
  text = ''
8
+ for page in pdf.pages:
9
+ text += page.extract_text()
 
 
10
  return text
11
 
12
  def translate_text(text, dest_lang='en'):
 
19
  translation = translate_text(text)
20
  return translation
21
 
22
+ iface = gr.Interface(fn=translate_pdf,
23
+ inputs=gr.inputs.File(label="Upload PDF file to translate"),
24
+ outputs='text',
25
+ title="PDF Translation App",
26
+ description="Use this application to translate from foreign language to English. Push 'Run' button when ready to translate.")
27
  iface.launch()