Spaces:
Build error
Build error
File size: 1,111 Bytes
f37cfad |
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 datasets import load_dataset
from PIL import Image
from collections import OrderedDict
from random import sample
import csv
title="ImageNet Roulette"
description="Try guessing the category of each image displayed, from the options provided below.\
After 10 guesses, we will show you your accuracy!\
"
classdict = OrderedDict()
for line in open('LOC_synset_mapping.txt', 'r').readlines():
try:
classdict[line.split(' ')[0]]= ' '.join(line.split(' ')[1:]).replace('\n','')
except:
continue
imagedict={}
with open('image_labels.csv', 'r') as csv_file:
reader = csv.DictReader(csv_file)
for row in reader:
imagedict[row['image_name']] = row['image_label']
def check_answer(im):
return {'cat': 0.3, 'dog': 0.7}
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
im = Image.open('images/'+sample(imagedict.keys(),1)[0]+'.jpg')
image = gr.Image(im,shape=(224, 224))
radio = gr.Radio(["option1", "option2", "option3"], label="Pick a category")
demo.launch()
|