|
|
|
|
|
|
|
__all__ = ['learn50', 'labels', 'image', 'examples', 'title', 'description', 'article', 'intfr', 'classify_image'] |
|
|
|
|
|
from fastai.vision.all import * |
|
import gradio as gr |
|
|
|
|
|
learn50 = load_learner('filmstars50.pkl') |
|
|
|
|
|
labels = learn50.dls.vocab |
|
def classify_image(pic): |
|
pred,pred_idx,probs = learn50.predict(PILImage.create(pic)) |
|
|
|
return {labels[i]: float(probs[i]) for i in range(len(labels))} |
|
|
|
|
|
|
|
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) |
|
|