Spaces:
Runtime error
Runtime error
app pronto
Browse files- .gitignore +2 -0
- app.py +34 -0
- teste.jpg +0 -0
.gitignore
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
teste.ipynb
|
2 |
+
.ipynb_checkpoints/teste-checkpoint.ipynb
|
app.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from fastai.vision.all import *
|
3 |
+
import requests
|
4 |
+
|
5 |
+
# learn = load_learner('bedroom_or_kitchen.pkl', 'rb')
|
6 |
+
|
7 |
+
# categories = ("Bedroom", "Kitchen")
|
8 |
+
|
9 |
+
# def classify_image(img):
|
10 |
+
# pred, idx, probs = learn.predict(img)
|
11 |
+
# return dict(zip(categories, map(float, probs)))
|
12 |
+
|
13 |
+
def get_ocr_prediction(img):
|
14 |
+
url = 'https://app.nanonets.com/api/v2/OCR/Model/50440c27-8fb2-4644-a156-75ce1a3c7586/LabelFile/?async=false'
|
15 |
+
|
16 |
+
data = {'file': open(img, 'rb')}
|
17 |
+
|
18 |
+
response = requests.post(url, auth=requests.auth.HTTPBasicAuth('Dpe3_Fz3XZoYtzMN8nUtsmcDh5t4QYnG', ''), files=data)
|
19 |
+
|
20 |
+
buyer_name = [a for a in response.json()["result"][0]["prediction"] if a["label"]=="buyer_name"][0]["ocr_text"]
|
21 |
+
buyer_address = [a for a in response.json()["result"][0]["prediction"] if a["label"]=="buyer_address"][0]["ocr_text"]
|
22 |
+
text = buyer_name+";"+buyer_address
|
23 |
+
|
24 |
+
return text
|
25 |
+
|
26 |
+
|
27 |
+
image = gr.inputs.Image(shape=(192, 192))
|
28 |
+
text = gr.outputs.Textbox()
|
29 |
+
|
30 |
+
examples = ['teste.jpg']
|
31 |
+
|
32 |
+
intf = gr.Interface(fn=get_ocr_prediction, inputs=image, outputs=text, examples=examples)
|
33 |
+
|
34 |
+
intf.launch()
|
teste.jpg
ADDED