File size: 1,257 Bytes
a852064
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
42
43
44
45
46
47
48
# app.py
from utils import load_model, predict
import torch
import json
import requests
import io
from PIL import Image
import streamlit as st

st.title('Dog Breed Classification')

# set header
st.header('Please upload a image')

# upload file
file = st.file_uploader('', type=['jpeg', 'jpg', 'png'])
url = st.text_input("Or enter image URL:")
st.button("Load Image")

# load classifier
model = load_model('model_scripted.pt')

if file is not None:
    image = Image.open(file).convert('RGB')
    st.image(image, use_column_width=True)

    # classify image
    predicted, probability = predict(model, image)

    # write classification
    st.write("## {}".format(predicted))
    st.write("### Probability: {}%".format(int(probability * 100)))

if url != '':
    try:
        response = requests.get(url)
        image = Image.open(io.BytesIO(response.content)).convert('RGB')
        st.image(image, caption="Image from URL", use_column_width=True)

        # classify image
        predicted, probability = predict(model, image)

        # write classification
        st.write("## {}".format(predicted))
        st.write("### score: {}%".format(int(probability * 100)))

    except Exception as e:
        st.error(f"Error loading image from URL: {e}")