Spaces:
Runtime error
Runtime error
correcao erro import image
Browse files- app.py +9 -2
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 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 |
|
|
@@ -12,8 +14,11 @@ import requests
|
|
| 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(
|
| 17 |
|
| 18 |
response = requests.post(url, auth=requests.auth.HTTPBasicAuth('Dpe3_Fz3XZoYtzMN8nUtsmcDh5t4QYnG', ''), files=data)
|
| 19 |
|
|
@@ -21,10 +26,12 @@ def get_ocr_prediction(img):
|
|
| 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(
|
| 28 |
text = gr.outputs.Textbox()
|
| 29 |
|
| 30 |
examples = ['teste.jpg']
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
# from fastai.vision.all import *
|
| 3 |
import requests
|
| 4 |
+
from PIL import Image
|
| 5 |
+
import os
|
| 6 |
|
| 7 |
# learn = load_learner('bedroom_or_kitchen.pkl', 'rb')
|
| 8 |
|
|
|
|
| 14 |
|
| 15 |
def get_ocr_prediction(img):
|
| 16 |
url = 'https://app.nanonets.com/api/v2/OCR/Model/50440c27-8fb2-4644-a156-75ce1a3c7586/LabelFile/?async=false'
|
| 17 |
+
|
| 18 |
+
img = Image.fromarray(img, 'RGB')
|
| 19 |
+
img.save('predict.jpg')
|
| 20 |
|
| 21 |
+
data = {'file': open('predict.jpg', 'rb')}
|
| 22 |
|
| 23 |
response = requests.post(url, auth=requests.auth.HTTPBasicAuth('Dpe3_Fz3XZoYtzMN8nUtsmcDh5t4QYnG', ''), files=data)
|
| 24 |
|
|
|
|
| 26 |
buyer_address = [a for a in response.json()["result"][0]["prediction"] if a["label"]=="buyer_address"][0]["ocr_text"]
|
| 27 |
text = buyer_name+";"+buyer_address
|
| 28 |
|
| 29 |
+
os.remove('predict.jpg')
|
| 30 |
+
|
| 31 |
return text
|
| 32 |
|
| 33 |
|
| 34 |
+
image = gr.inputs.Image()
|
| 35 |
text = gr.outputs.Textbox()
|
| 36 |
|
| 37 |
examples = ['teste.jpg']
|
requirements.txt
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
requests
|
|
|
|
|
|
| 1 |
+
requests
|
| 2 |
+
PIL
|