|
import gradio as gr |
|
import pandas as pd |
|
|
|
from fastbook import * |
|
from fastai.vision.widgets import * |
|
from fastai.vision.all import * |
|
|
|
|
|
|
|
|
|
|
|
learn = load_learner('model.pkl') |
|
|
|
categories = learn.dls.vocab |
|
|
|
|
|
df_sort = pd.read_csv('Lista.csv',sep =";").set_index('Avfall') |
|
|
|
def classify_image(img): |
|
|
|
trash,idx,probs = learn.predict(PILImage.create(img)) |
|
df = pd.DataFrame() |
|
df['categories'] = categories |
|
df['probabilities'] = probs.numpy() |
|
sorted_df = df.sort_values(by=['probabilities'], ascending=False).head() |
|
predictions = dict(zip(sorted_df['categories'].tolist(),map(float,sorted_df['probabilities'].tolist()))) |
|
|
|
|
|
|
|
sort_text = "Sorteras som " + df_sort.loc[trash].tolist()[0] |
|
return "Det där är...", predictions, sort_text |
|
|
|
|
|
image = gr.Image(type='pil') |
|
label = ["text",gr.Label(),"text"] |
|
|
|
iface = gr.Interface(fn=classify_image, inputs=image, outputs=label) |
|
iface.launch() |