File size: 1,227 Bytes
df21123
eed6669
df21123
eed6669
edb46f7
 
df21123
eed6669
edb46f7
df21123
edb46f7
df21123
 
 
 
 
 
edb46f7
 
 
df21123
 
edb46f7
 
df21123
edb46f7
df21123
 
 
 
 
 
 
 
edb46f7
 
 
 
 
 
 
521641c
edb46f7
 
df21123
eed6669
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
from fastai.vision.all import *
import gradio as gr
import os


def house_room(x):
    return x[0].isupper()


# Load the learner model
learn_inf = load_learner("model/model.pkl")

categories = learn_inf.dls.vocab

# Log the categories
print(categories)

# Comma separated string of categories with and between the last two
categories_str = ", ".join(categories[:-1]) + " or " + categories[-1]

def classify_image(img):
    pred, idx, probs = learn_inf.predict(img)
    return {f"{categories[idx]}": float(probs[idx])}


image = gr.Image(sources=["upload"], label="Image")
label = gr.Label()

# Load the images from the examples folder
examples = []
for file in os.listdir("images/examples"):
    if file.endswith(".jpg"):
        examples.append([f"images/examples/{file}"])

iface = gr.Interface(
    fn=classify_image,
    inputs=image,
    outputs=label,
    examples=examples,
    analytics_enabled=False,
    title="<h1>House Room Classifier</h1>",
    description='<p style = "font-size: 1.4rem;">This model classifies a photo of a house room as either <strong>' + categories_str + '</strong>.</p><p style = "font-size: 1.2rem;">Upload an image or use the examples below.</p>',
    flagging_options=[],
)

iface.launch()