Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from detection import app as detector | |
| from recognition import app_easyocr | |
| from PIL import Image | |
| import requests | |
| import os | |
| def recognize(img_arr = None, img_url = None): | |
| if img_arr == None and img_url != None: | |
| print('downloading image....') | |
| img_arr = Image.open(requests.get(img_url, stream=True).raw) | |
| if img_arr == None: | |
| print('choose image or type the url!') | |
| return | |
| detections = detector.detect(img_arr) | |
| img_arr, numbers = app_easyocr.extract_number(img_arr, detections) | |
| return img_arr, numbers | |
| def use_example(url): | |
| img_arr = Image.open(requests.get(url, stream=True).raw) | |
| return recognize(img_arr) | |
| input_image = gr.Image(type="pil") | |
| input_text = gr.Textbox(lines=1, label='Or Image Url', placeholder="paste image url here...") | |
| output_img = gr.Image(type='pil') | |
| output_json = gr.JSON() | |
| example_url = gr.Examples( | |
| examples=['https://storage.googleapis.com/pic2go-prod-photos/photos/5764746996613120/noContext/5933759615205376.jpg'], | |
| inputs=input_text, | |
| outputs=[output_img, output_json], | |
| fn=use_example, | |
| cache_examples=True) | |
| demo = gr.Interface(fn=recognize, | |
| inputs=[input_image, input_text], | |
| outputs=[output_img, output_json], | |
| # examples=example_url, | |
| description='BIB Race Number Recognition') | |
| if __name__ == "__main__": | |
| demo.launch() | |
| # demo.launch() | |