Spaces:
Build error
Build error
File size: 1,157 Bytes
fb66768 9f4536a fb66768 cab8b72 77cc002 fb66768 7d22f6a 77cc002 7d22f6a |
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 41 42 43 |
import gradio as gr
from fastai.vision.all import *
import timm
import random
import pickle
infile = open('gamename_dict.pkl','rb')
game_name_dict = pickle.load(infile)
infile.close()
learn=load_learner('convnext_nano_4freeze_5epochs_on_jpg_26error.pkl')
categories=learn.dls.vocab
categories=[game_name_dict[gn] for gn in categories]
def recognize_game(img):
img= PILImage.create(img)
pred,idx,probs=learn.predict(img)
return pred,str(100*float(dict(zip(categories, probs))[pred]))[:4]+"%"
def recognize_game_all(img):
img= PILImage.create(img)
pred,idx,probs=learn.predict(img)
img.save(pred+str(random.randrange(1,10000))+'.jpg')
return dict(zip(categories, map(float,probs)))
#image = gr.inputs.Image(shape=(224,224))
image = gr.inputs.Image()
label = gr.outputs.Label(num_top_classes=48)
title= 'A Game For That - Gamification Using Snapshot Images'
# examples = ['image.jpg','1.1.jpg','1.2.jpg','2.jpg','3.jpg','4.jpg', '5.jpg' ]
iface = gr.Interface(
fn=recognize_game_all,
inputs=image,
outputs=label,
title=title,
#examples=examples
)
#iface.launch(inline=False)
iface.launch(debug=True)
|