Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import easyocr as ocr #OCR
|
2 |
+
from PIL import Image #Image Processing
|
3 |
+
import numpy as np #Image Processing
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
|
7 |
+
input = gr.inputs.Image(label="Upload your Image", type = type=['png','jpg','jpeg'], optional=True)
|
8 |
+
|
9 |
+
def load_model():
|
10 |
+
reader = ocr.Reader(['en'],model_storage_directory='.')
|
11 |
+
return reader
|
12 |
+
|
13 |
+
def text(image):
|
14 |
+
reader = load_model() #load model
|
15 |
+
input_image = Image.open(image) #read image
|
16 |
+
result = reader.readtext(np.array(input_image))
|
17 |
+
result_text = [] #empty list for results
|
18 |
+
for text in result:
|
19 |
+
result_text.append(text[1])
|
20 |
+
return result_text
|
21 |
+
|
22 |
+
output = gr.outputs.Textbox(type="text",label="Captions")
|
23 |
+
|
24 |
+
title = "Image Captioning "
|
25 |
+
|
26 |
+
interface = gr.Interface(
|
27 |
+
fn=text,
|
28 |
+
inputs = input,
|
29 |
+
theme="grass",
|
30 |
+
outputs=output,
|
31 |
+
title=title,
|
32 |
+
)
|
33 |
+
interface.launch(debug=True)
|