|
import gradio as gr |
|
from transformers import AutoModelForImageClassification, AutoProcessor |
|
import torch |
|
|
|
|
|
model_name = "dima806/facial_age_image_detection" |
|
model = AutoModelForImageClassification.from_pretrained(model_name) |
|
processor = AutoProcessor.from_pretrained(model_name) |
|
|
|
|
|
def predict(image): |
|
|
|
inputs = processor(images=image, return_tensors="pt") |
|
|
|
with torch.no_grad(): |
|
outputs = model(**inputs) |
|
|
|
|
|
predictions = outputs.logits |
|
|
|
|
|
predictions_list = predictions.tolist() |
|
rounded_predictions = [[round(pred, 2) for pred in prediction] for prediction in predictions_list] |
|
|
|
return rounded_predictions |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict, |
|
inputs="image", |
|
outputs="label", |
|
title="Facial Age Prediction", |
|
description="This application predicts your age from a facial image." |
|
) |
|
|
|
|
|
iface.launch(share=True) |
|
|