Antoine245's picture
Update app.py
2c92669
raw
history blame
681 Bytes
import torch
import gradio as gr
import json
from transformers import pipeline
device = "cuda" if torch.cuda.is_available() else "cpu"
def predict(image):
classifier = pipeline(task="image-classification")
preds = classifier(image)
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
prediction_json = json.dumps(preds)
prediction_dict = json.loads(prediction_json)
return prediction_dict
description = """
"""
gr.Interface(
fn=predict,
inputs=[
gr.inputs.Image(label="Image to classify", type="pil"),
],
outputs="label",
title="Comparateur d'image",
description=description
).launch()