File size: 697 Bytes
1bac567
 
464daab
 
1bac567
 
 
 
 
f9eade5
1bac567
32c8cb6
1bac567
 
d9e4675
 
1bac567
 
 
 
2937c48
b080adc
1bac567
 
 
 
 
 
126573d
1bac567
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
import os 
import huggingface_hub as hf_hub
import gradio as gr

client = hf_hub.InferenceClient(token = os.environ['HF_TOKEN'])
client.headers["x-use-cache"] = "0" 

def predict(image, label_list):
    labels = label_list.split(",")
    response = client.zero_shot_image_classification(
        image,
        labels
    )

    result = {v['label'] : v['score'] for v in response}
    return result

app = gr.Interface(
    fn = predict, 
    inputs = [
        gr.Image(type = 'filepath'), 
        gr.Textbox(label = 'Image class list (separated by comma)')
    ], 
    outputs = gr.Label(), 
    title = 'Zero Shot Image Classification',
    description = 'Vinay Kumar Thakur'
)


app.launch()