Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,19 @@
|
|
1 |
import os
|
2 |
import gradio as gr
|
|
|
3 |
from transformers import pipeline
|
4 |
import huggingface_hub
|
5 |
|
6 |
-
|
|
|
|
|
7 |
|
8 |
# Load the pre-trained model
|
9 |
classifier = pipeline("text-classification", model="ICILS/xlm-r-icils-ilo", device=0)
|
10 |
|
11 |
# Define the prediction function
|
|
|
12 |
def classify_text(text):
|
13 |
-
"""
|
14 |
-
Classify the input text into occupational categories using a pre-trained model.
|
15 |
-
|
16 |
-
Args:
|
17 |
-
text (str): Job description text.
|
18 |
-
|
19 |
-
Returns:
|
20 |
-
tuple: (label, score) - The classification label and the associated confidence score.
|
21 |
-
"""
|
22 |
result = classifier(text)[0]
|
23 |
label = result['label']
|
24 |
score = result['score']
|
@@ -27,15 +22,11 @@ def classify_text(text):
|
|
27 |
# Create the Gradio interface
|
28 |
demo = gr.Interface(
|
29 |
fn=classify_text,
|
30 |
-
inputs=gr.Textbox(lines=2, label="Job
|
31 |
outputs=[gr.Textbox(label="ISCO-08 Label"), gr.Number(label="Score")],
|
32 |
-
title="XLM-R ISCO
|
33 |
-
description=
|
34 |
-
"Classify job descriptions into occupational categories using a pre-trained XLM-R-ISCO model "
|
35 |
-
"from Hugging Face Spaces."
|
36 |
-
),
|
37 |
)
|
38 |
|
39 |
-
# Run the Gradio app
|
40 |
if __name__ == "__main__":
|
41 |
-
demo.launch()
|
|
|
1 |
import os
|
2 |
import gradio as gr
|
3 |
+
import spaces
|
4 |
from transformers import pipeline
|
5 |
import huggingface_hub
|
6 |
|
7 |
+
# Login to Hugging Face Hub
|
8 |
+
token = os.getenv("HF_TOKEN")
|
9 |
+
huggingface_hub.login(token=token)
|
10 |
|
11 |
# Load the pre-trained model
|
12 |
classifier = pipeline("text-classification", model="ICILS/xlm-r-icils-ilo", device=0)
|
13 |
|
14 |
# Define the prediction function
|
15 |
+
@spaces.GPU
|
16 |
def classify_text(text):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
result = classifier(text)[0]
|
18 |
label = result['label']
|
19 |
score = result['score']
|
|
|
22 |
# Create the Gradio interface
|
23 |
demo = gr.Interface(
|
24 |
fn=classify_text,
|
25 |
+
inputs=gr.Textbox(lines=2, label="Job description text", placeholder="Enter a job description..."),
|
26 |
outputs=[gr.Textbox(label="ISCO-08 Label"), gr.Number(label="Score")],
|
27 |
+
title="XLM-R ISCO classification with ZeroGPU",
|
28 |
+
description="Classify occupations using a pre-trained XLM-R-ISCO model on Hugging Face Spaces with ZeroGPU"
|
|
|
|
|
|
|
29 |
)
|
30 |
|
|
|
31 |
if __name__ == "__main__":
|
32 |
+
demo.launch()
|