Update app.py
Browse files
app.py
CHANGED
@@ -1,46 +1,41 @@
|
|
1 |
-
import
|
2 |
-
import
|
3 |
from transformers import pipeline
|
|
|
4 |
|
5 |
-
# Load translation and summarization pipelines
|
6 |
-
translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
|
7 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
8 |
|
9 |
-
# Function to translate and summarize text
|
10 |
-
def translate_and_summarize(text):
|
11 |
-
translated_text = translator(text)[0]['translation_text']
|
12 |
-
summary = 'News Alert. ' + summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
|
13 |
-
return summary
|
14 |
|
15 |
-
#
|
16 |
-
|
17 |
-
first_sentence = text.split('.')[0] + '.'
|
18 |
-
translated_text = translator(first_sentence)[0]['translation_text']
|
19 |
-
summary = summarizer(translated_text, max_length=20, min_length=5, do_sample=False)[0]['summary_text']
|
20 |
-
return summary
|
21 |
|
22 |
-
#
|
23 |
-
def
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
# Display data in a table
|
38 |
-
st.write(data[['ID', 'Title', 'DescriptionEn']])
|
39 |
-
# Provide download link for the updated CSV
|
40 |
-
csv = data.to_csv(index=False)
|
41 |
-
st.download_button(label="Download updated CSV", data=csv, file_name="updated_data.csv", mime="text/csv")
|
42 |
-
else:
|
43 |
-
st.error("Uploaded CSV does not contain required 'Description' column.")
|
44 |
|
|
|
45 |
if __name__ == "__main__":
|
46 |
-
|
|
|
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']
|
25 |
+
return label, score
|
26 |
|
27 |
+
# Create the Gradio interface
|
28 |
+
demo = gr.Interface(
|
29 |
+
fn=classify_text,
|
30 |
+
inputs=gr.Textbox(lines=2, label="Job Description Text", placeholder="Enter a job description..."),
|
31 |
+
outputs=[gr.Textbox(label="ISCO-08 Label"), gr.Number(label="Score")],
|
32 |
+
title="XLM-R ISCO Classification",
|
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()
|