|
import io |
|
import base64 |
|
import requests |
|
import numpy as np |
|
import gradio as gr |
|
|
|
from PIL import Image |
|
from io import BytesIO |
|
|
|
|
|
def image_classifier(image, api_key): |
|
|
|
buffered = io.BytesIO() |
|
image = Image.fromarray(np.uint8(image)) |
|
image = image.convert("RGB") |
|
image.save(buffered, quality=90, format="JPEG") |
|
img_str = base64.b64encode(buffered.getvalue()) |
|
img_str = img_str.decode("ascii") |
|
|
|
|
|
headers = {'Content-Type': 'application/json', 'accept': 'application/json'} |
|
r = requests.post(f'https://classify.roboflow.com/clasificacion-sin-regularizacion/1?api_key={api_key}', |
|
data=img_str, |
|
headers=headers) |
|
preds = r.json() |
|
|
|
|
|
output = {x:round(float(y['confidence']), 3) for x,y in preds['predictions'].items()} |
|
return output |
|
|
|
|
|
demo = gr.Interface(fn=image_classifier, inputs=["image", "text"], outputs="label") |
|
demo.launch(debug=True) |