Fralet commited on
Commit
04bbd33
·
verified ·
1 Parent(s): 688b656

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -38
app.py CHANGED
@@ -1,46 +1,41 @@
1
- import streamlit as st
2
- import pandas as pd
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
- # Function to translate and summarize first paragraph
16
- def translate_and_summarize_first_paragraph(text):
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
- # Streamlit interface
23
- def main():
24
- st.title("CSV Translator and Summarizer")
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- # File uploader
27
- uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
28
- if uploaded_file is not None:
29
- # Read data
30
- data = pd.read_csv(uploaded_file)
31
- # Check if 'Description' and 'Published' columns exist
32
- if 'Description' in data.columns:
33
- # Apply full translation and summarization
34
- data['DescriptionEn'] = data['Description'].apply(translate_and_summarize)
35
- # Apply first paragraph translation and summarization for Title
36
- data['Title'] = data['Description'].apply(translate_and_summarize_first_paragraph)
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
- main()
 
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()