File size: 1,171 Bytes
04bbd33
 
91dd84e
04bbd33
240b689
19dc535
0f375b6
04bbd33
 
19dc535
04bbd33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19dc535
04bbd33
 
 
 
 
 
 
 
 
 
 
225ca46
04bbd33
88c381a
04bbd33
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
41
42
import os
import gradio as gr
from transformers import pipeline
import huggingface_hub



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

# Define the prediction function
def classify_text(text):
    """
    Classify the input text into occupational categories using a pre-trained model.
    
    Args:
        text (str): Job description text.
    
    Returns:
        tuple: (label, score) - The classification label and the associated confidence score.
    """
    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",
    description=(
        "Classify job descriptions into occupational categories using a pre-trained XLM-R-ISCO model "
        "from Hugging Face Spaces."
    ),
)

# Run the Gradio app
if __name__ == "__main__":
    demo.launch()