File size: 1,138 Bytes
9d4f900
 
 
0ecbfab
9565e59
5702361
9d4f900
0c74d5c
94d7ce8
 
 
 
 
 
9d4f900
 
e0ce9de
9d4f900
 
9565e59
9d4f900
9565e59
9d4f900
 
 
9565e59
9d4f900
 
9565e59
9d4f900
 
 
 
 
 
 
 
 
 
 
 
 
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
__all__ = [
    'learn', 'classify_image', 'categories', 'image', 'label', 'examples', 'intf'
]

from fastai.vision.all import *
import gradio as gr
import timm  # keep only if your model actually needs timm

def is_real(x):
    # Recreate the original function used during training
    # Example: return x > 0.5 or whatever logic you had
    pass  # Replace with actual logic


# βœ… Load the fastai model properly β€” no manual pickle.load()
learn = load_learner('model.pkl', cpu=True)

# Define your categories exactly as trained
categories = ('Virtual Staging', 'Real')

# Prediction function for Gradio
def classify_image(img):
    pred, idx, probs = learn.predict(img)
    # Cast to float so Gradio handles them cleanly
    return dict(zip(categories, map(float, probs)))

# Gradio UI components
image = gr.inputs.Image(shape=(192, 192))
label = gr.outputs.Label()
examples = ['virtual.jpg', 'real.jpg']  # sample files in your Space

# Create and launch interface
intf = gr.Interface(
    fn=classify_image,
    inputs=image,
    outputs=label,
    examples=examples,
    share=True
)

if __name__ == "__main__":
    intf.launch()