sorting_hat / app.py
merve's picture
merve HF Staff
Update app.py
0ea9639
raw
history blame contribute delete
949 Bytes
from huggingface_hub import from_pretrained_keras
import gradio as gr
import numpy as np
import tensorflow
model = from_pretrained_keras("merve/riddikulus")
labels = {0:"Ravenclaw πŸ¦…πŸ’™ ", 1:"Gryffindor 🦁", 2:"Ravenclaw πŸ¦…πŸ’™",3:"SlytherinπŸπŸ’š",
4:"Hufflepuff πŸ¦‘πŸ’›", 5:"Death eater detected! ", 6: "Hufflepuff πŸ¦‘πŸ’›", 7:"SlytherinπŸπŸ’š",
8:"Ravenclaw πŸ¦…πŸ’™", 9:"Gryffindor 🦁"}
canvas = gr.inputs.Image(source="canvas", shape=(28,28))
text = gr.outputs.Textbox()
def infer(image):
cls = np.argmax(model.predict(np.expand_dims(image, axis = 0)[:,:,:,1]))
if cls == 5:
output = "Death eater detected! πŸ’€"
else:
cls = labels[cls]
output = f"Welcome to {cls}"
return output
gr.Interface(infer, inputs=[canvas], outputs=[text], title="Welcome to Hogwarts Sorting Hat!", description="Draw something and let the sorting hat sort you! 🎩 ").launch()