File size: 1,286 Bytes
163ec32
7000e84
 
6badb61
7000e84
6badb61
 
163ec32
 
6badb61
84f5277
6badb61
 
 
 
 
 
 
 
84f5277
163ec32
4c52049
 
84f5277
4c52049
0e6fdc4
84f5277
163ec32
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
import gradio as gr
from transformers import pipeline

# Initialize pipelines
crop_pipe = pipeline("image-classification", model="LucyintheSky/pose-estimation-crop-uncrop")
pose_pipe = pipeline("image-classification", model="LucyintheSky/pose-estimation-front-side-back")
name_pipe = pipeline("image-classification", model="LucyintheSky/model-prediction")

def classify(img):
    # Classify image
    crop = crop_pipe(img)
    pose = pose_pipe(img)
    name = name_pipe(img)
    
    # Format results
    result = crop[0]['label'] + ' (' + str(int(float(crop[0]['score']) * 100)) + '%)\n'
    result += pose[0]['label'] + ' (' + str(int(float(pose[0]['score']) * 100)) + '%)\n'
    result += name[0]['label'] + ' (' + str(int(float(name[0]['score']) * 100)) + '%)'
    
    return result

iface = gr.Interface(fn=classify,
                     title='Product Photo Classifier',
                     inputs=gr.Image(label='Image', type='filepath'), 
                     outputs=gr.Textbox(label='Classification'),
                     examples=[['./images/1.jpg'],['./images/2.jpg'],['./images/3.jpg']],
                     theme=gr.themes.Base(primary_hue=gr.themes.colors.pink, secondary_hue=gr.themes.colors.gray, neutral_hue=gr.themes.colors.slate, font=["avenir"]))
iface.launch()