Upload app.py
Browse files1234567891011121314151617181920212223242526272829303132333435363738394041# AUTOGENERATED! DO NOT EDIT! File to edit: ../movie_genre.ipynb.
# %% auto 0__all__ = ['path', 'learn', 'labels', 'title', 'description', 'examples', 'pred']
# %% ../movie_genre.ipynb 1from fastai.vision.all import *
# %% ../movie_genre.ipynb 2path = Path()path.ls(file_exts='.pkl')
# %% ../movie_genre.ipynb 3learn = load_learner(path/'model.pkl')
# %% ../movie_genre.ipynb 4labels = learn.dls.vocab # [animation, fantasy, romance]
# %% ../movie_genre.ipynb 6# Prediction functiondef 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 7import gradio as gr
# %% ../movie_genre.ipynb 8title = '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)app.pyAdded+41