File size: 1,037 Bytes
923f66c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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)


@st.cache(allow_output_mutation=True)
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)