File size: 1,164 Bytes
8674047
 
 
 
 
 
0c633e0
8674047
 
0c633e0
8674047
0c633e0
8674047
dff06db
 
72c5c6e
628f938
 
8674047
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from fastai.vision.all import *
import gradio as gr

# Load the model
learn = load_learner('model.pkl')

# Define the prediction function
def predict(img):
    try:
        # Create the image object
        img = PILImage.create(img)
        # Get predictions from the model
        pred, pred_idx, probs = learn.predict(img)
        # Fetch the labels dynamically from the model's vocabulary
        labels = learn.dls.vocab
        # Ensure probabilities are floats
        return {labels[i]: float(probs[i]) for i in range(len(labels))}

    except Exception as e:
        # Log the exception and return it as an error message
        print(f"An error occurred: {e}")
        return {"error": str(e)}

# Define the Gradio interface
title = "Interior Design Classifier"
description = "Upload an image of an interior design and get a prediction of the design style."
examples = ['1.jpeg', '2.jpg', '3.jpg']

# Set up Gradio interface
interface = gr.Interface(
    fn=predict,
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=3),
    title=title,
    description=description,
    examples=examples
)

interface.launch(share=True, debug=False)