File size: 960 Bytes
fc1183e
5abb6ea
 
b0b048d
c54a3f3
5abb6ea
352ade9
b0b048d
c54a3f3
b0b048d
 
352ade9
b0b048d
 
5abb6ea
b0b048d
043d807
 
 
 
c8cfe36
b0b048d
 
 
7ad6122
 
b0b048d
 
 
 
352ade9
 
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
import os
import gradio as gr
import spaces
from transformers import pipeline
import huggingface_hub

# Login to Hugging Face Hub
token = os.getenv("HF_TOKEN")
huggingface_hub.login(token=token)

# Load the pre-trained model
classifier = pipeline("text-classification", model="ICILS/xlm-r-icils-ilo", device=0)

# Define the prediction function
@spaces.GPU
def classify_text(text):
    result = classifier(text)[0]
    label = result['label']
    score = result['score']
    return label, score

# Create the Gradio interface
demo = gr.Interface(
    fn=classify_text,
    inputs=gr.Textbox(lines=2, label="Job description text", placeholder="Enter a job description..."),
    outputs=[gr.Textbox(label="ISCO-08 Label"), gr.Number(label="Score")],
    title="XLM-R ISCO classification with ZeroGPU",
    description="Classify occupations using a pre-trained XLM-R-ISCO model on Hugging Face Spaces with ZeroGPU"
)

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