pizurny's picture
Update app.py
a19958b verified
raw
history blame contribute delete
945 Bytes
from fastai.vision.all import *
from pathlib import Path
# Load the model with WindowsPath issue
learn = load_learner('babis_fico_classifier.pkl')
# Re-save the model in the current Linux environment (removing WindowsPath issues)
learn.export('babis_fico_classifier_linux.pkl')
# Load the newly saved model
learn = load_learner('babis_fico_classifier_linux.pkl')
# Define the prediction function
def predict_image(img):
pred, pred_idx, probs = learn.predict(img)
return {learn.dls.vocab[i]: float(probs[i]) for i in range(len(probs))}
# Set up the Gradio interface
import gradio as gr
image_input = gr.Image(type="pil")
label_output = gr.Label(num_top_classes=2)
interface = gr.Interface(fn=predict_image, inputs=image_input, outputs=label_output,
title="Babiš vs Fico Classifier",
description="Upload an image of Robert Fico or Andrej Babiš to classify.")
interface.launch()