Download app.py from anijyi/testing: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/spaces/anijyi/testing/resolve/main/app.py
- Command line
-
hf download hf://spaces/anijyi/testing/app.py
-
curl -L -o app.py https://huggingface.co/spaces/anijyi/testing/resolve/main/app.py
1.24 kB
| # AUTOGENERATED! DO NOT EDIT! File to edit: ../movie_genre.ipynb. | |
| # %% auto 0 | |
| __all__ = ['path', 'learn', 'labels', 'title', 'description', 'examples', 'pred'] | |
| # %% ../movie_genre.ipynb 1 | |
| from fastai.vision.all import * | |
| # %% ../movie_genre.ipynb 2 | |
| path = Path() | |
| path.ls(file_exts='.pkl') | |
| # %% ../movie_genre.ipynb 3 | |
| learn = load_learner(path/'model.pkl') | |
| # %% ../movie_genre.ipynb 4 | |
| labels = learn.dls.vocab # [animation, fantasy, romance] | |
| # %% ../movie_genre.ipynb 6 | |
| # Prediction function | |
| def pred(image): | |
| img = PILImage.create(image) | |
| pred, pred_idx, prob = learn.predict(img) | |
| return {labels[i]: float(prob[i]) for i in range(len(labels))} | |
| # return labels[pred_idx], float(prob) | |
| # %% ../movie_genre.ipynb 7 | |
| import gradio as gr | |
| # %% ../movie_genre.ipynb 8 | |
| title = 'Movie Genre Classifier' | |
| description = 'A classifier trained on various movie scenes to classify them as romance, fantasy, or animation.' | |
| examples = ['animation.jpg', 'fantasy.jpg', 'romance.jpg'] | |
| gr.Interface(fn=pred, | |
| inputs='image', | |
| outputs='label', | |
| title=title, | |
| description=description, | |
| examples=examples, | |
| theme='ParityError/Interstellar').launch(share=True) | |