File size: 1,260 Bytes
7b81e42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3ba28db
 
f27b080
3ba28db
 
 
7b81e42
 
3ba28db
7b81e42
 
 
 
a211509
7b81e42
 
 
 
 
 
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
49
import gradio as gr
from fastai.vision.all import load_learner

# Custom CSS for the app (remove background color from examples)
custom_css = """
body { background-color: #1E1E1E; color: #F5F5F5; }
.gradio-container { max-width: 800px; margin: auto; }
.input-panel, .output-panel { 
    background-color: #2E2E2E; 
    border: 2px solid #00BFFF; 
    border-radius: 10px; 
    box-shadow: 0 0 10px #00BFFF; 
    padding: 20px; 
    margin: 10px; 
}
button { 
    background: linear-gradient(90deg, #00BFFF, #FF6B6B); 
    border: none; 
    color: #F5F5F5; 
    padding: 2px 5px;  
    border-radius: 2px;
    cursor: pointer; 
}
button:hover { 
    box-shadow: 0 0 10px #00BFFF; 
}
"""

def classify_img(img) -> dict:
    """helper function to generate predictions"""
    
    lbls = ['Cat', 'Dog']
    preds, idx, probs = model.predict(img)
    
    return dict(zip(lbls, map(float, probs)))

# load model
model = load_learner('model_2_ep_new_data.pkl')

# build app
image = gr.Image()
label = gr.Label()
examples = './inf_cs/'

app = gr.Interface(fn = classify_img, inputs = image, outputs = label, examples = examples, theme = 'earneleh/paris', css = custom_css,
examples_per_page = 7, flagging_mode = 'never', clear_btn = None)

app.launch()
# app.close()