Spaces:
Runtime error
Runtime error
Download app.py from merve/sorting_hat: direct link, hf CLI and curl.
- Browser
- Download file 949 Bytes
-
https://huggingface.co/spaces/merve/sorting_hat/resolve/main/app.py
- Command line
-
hf download hf://spaces/merve/sorting_hat/app.py
-
curl -L -o app.py https://huggingface.co/spaces/merve/sorting_hat/resolve/main/app.py
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() |