File size: 924 Bytes
a5df04e
 
 
 
 
 
46a1f9a
a5df04e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from turtle import title
import gradio as gr
from transformers import pipeline
from PIL import Image

# Initialize the pipeline with your model
pipe = pipeline("image-classification", model="SubterraAI/ofwat_material_classification")

def classify_image(image):
    # Convert the input image to PIL format
    PIL_image = Image.fromarray(image).convert('RGB')
    
    # Classify the image using the pipeline
    res = pipe(PIL_image)
    
    # Extract labels and scores
    return {dic["label"]: dic["score"] for dic in res}

# Create the Gradio interface
iface = gr.Interface(
    classify_image, 
    "image", 
    "label", 
    examples=[
        ["examples/CS.jpg"], 
        ["examples/GI.jpg"],
        ["examples/PP.jpg"],
        ["examples/RC.jpg"]
    ],
    description="Upload an image to classify its material.",
    title="Material Classification with AI by Subterra"
)

# Launch the interface
iface.launch()