FilmStars / app.py
Gavin Francis
Added blog post
9427311
raw
history blame contribute delete
No virus
1.19 kB
# AUTOGENERATED! DO NOT EDIT! File to edit: ../FilmStarsApp.ipynb.
# %% auto 0
__all__ = ['learn50', 'labels', 'image', 'examples', 'title', 'description', 'article', 'intfr', 'classify_image']
# %% ../FilmStarsApp.ipynb 2
from fastai.vision.all import *
import gradio as gr
# %% ../FilmStarsApp.ipynb 4
learn50 = load_learner('filmstars50.pkl')
# %% ../FilmStarsApp.ipynb 5
labels = learn50.dls.vocab
def classify_image(pic):
pred,pred_idx,probs = learn50.predict(PILImage.create(pic))
#ps, idxs = probs.topk(3)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
# %% ../FilmStarsApp.ipynb 7
image = gr.components.Image()
examples = ['Angelina Jolie.jpg','Penelope Cruz.jpg','Jack Nicholson.jpg']
title = "Identify film stars similar to your image"
description = "Try uploading a photograph of yourself"
article = "<p style='text-align: center'><a href='https://science4performance.com/2023/01/01/eddy-goes-to-hollywood/' target='_blank'>Blog post</a></p>"
intfr = gr.Interface(fn=classify_image, inputs=image, outputs=gr.components.Label(num_top_classes=3), examples=examples, title=title, description=description, article=article)
intfr.launch(inline=False)