Spaces:
Runtime error
Runtime error
import streamlit as st | |
from PIL import Image | |
from backend.pipeline import PreTrainedPipeline | |
import pandas as pd | |
import io | |
import matplotlib.pyplot as plt | |
import numpy as np | |
def import_fig(): | |
image = st.file_uploader("Upload your picture.", type=["png", "jpg", "jpeg"]) | |
if image: | |
bytes_image = image.getvalue() | |
image = Image.open(io.BytesIO(bytes_image)) | |
st.image(image, caption=["We are classifying this image..."]) | |
return image | |
def plot(data=None): | |
fig = plt.figure() | |
ax = fig.add_axes([0, 0, 1, 1]) | |
breeds = data.head(3)["label"].tolist() | |
labels = data.head(3)["score"].tolist() | |
ax.bar(breeds, labels) | |
ax.set_ylabel("Probability that your pet is breed X") | |
ax.grid("on") | |
st.pyplot(fig) | |
def fastai_model(image): | |
if image: | |
model = PreTrainedPipeline(path="backend") | |
outputs = model(image) | |
outputs_df = pd.DataFrame(outputs) | |
return outputs_df.sort_values(by=["score"], ascending=False) | |