Spaces:
Sleeping
Sleeping
File size: 894 Bytes
8822e83 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
from transformers import pipeline
import gradio as gr
_MODEL_NAME = "ruj"
_HF_USER = "universalml"
def prediction_function(input_file):
# get user name of their hugging face
model_path = _HF_USER + "/" + _MODEL_NAME
# takes some time
classifier = pipeline("image-classification", model=model_path)
try:
result = classifier(input_file)
predictions = dict()
labels = []
for each_label in result:
predictions[each_label["label"]] = each_label["score"]
labels.append(each_label["label"])
result = predictions
except:
result = "no data provided!!"
return result
# change _MODEL_NAME parameter
def create_demo():
demo = gr.Interface(
fn=prediction_function,
inputs=gr.Image(type="pil"),
outputs=gr.Label(num_top_classes=3),
)
demo.launch()
create_demo()
|