xavierbarbier commited on
Commit
704093d
·
verified ·
1 Parent(s): 0a6c70f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ from pypdf import PdfReader
4
+ import os
5
+
6
+ def extract_text(file):
7
+
8
+ """path = file
9
+ normalized_path = os.path.normpath(path)
10
+ normalized_path = normalized_path.replace("\\", "/")
11
+
12
+ # creating a pdf reader object
13
+ reader = PdfReader(file)
14
+
15
+ text = []
16
+ for p in np.arange(0, len(reader.pages), 1):
17
+ page = reader.pages[int(p)]
18
+
19
+ # extracting text from page
20
+ text.append(page.extract_text())
21
+
22
+ text = ' '.join(text)"""
23
+
24
+ return file
25
+
26
+ with gr.Blocks() as demo:
27
+ file_input = gr.File(label="Upload a PDF file")
28
+ text_output = gr.Textbox(label="Extracted Text")
29
+ file_input.upload(extract_text, inputs=file_input, outputs=text_output)
30
+
31
+ demo.launch()