Spaces:
Sleeping

File size: 1,235 Bytes
9c56ccf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# 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)