Update app.py
Browse files
app.py
CHANGED
@@ -5,18 +5,23 @@ from transformers import pipeline
|
|
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 |
-
title_generator = pipeline("text2text-generation", model="facebook/bart-large-cnn")
|
9 |
|
10 |
-
# Function to translate
|
11 |
-
def
|
12 |
translated_text = translator(text)[0]['translation_text']
|
13 |
summary = 'News Alert. ' + summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Streamlit interface
|
18 |
def main():
|
19 |
-
st.title("CSV Translator
|
20 |
|
21 |
# File uploader
|
22 |
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
@@ -25,13 +30,14 @@ def main():
|
|
25 |
data = pd.read_csv(uploaded_file)
|
26 |
# Check if 'Description' and 'Published' columns exist
|
27 |
if 'Description' in data.columns and 'Published' in data.columns:
|
28 |
-
# Apply translation
|
29 |
-
data[
|
30 |
-
lambda row:
|
31 |
)
|
|
|
|
|
32 |
# Display data in a table
|
33 |
-
st.write(data[['ID', 'Title', '
|
34 |
-
|
35 |
else:
|
36 |
st.error("Uploaded CSV does not contain required 'Description' and 'Published' columns.")
|
37 |
|
|
|
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")
|
|
|
30 |
data = pd.read_csv(uploaded_file)
|
31 |
# Check if 'Description' and 'Published' columns exist
|
32 |
if 'Description' in data.columns and 'Published' in data.columns:
|
33 |
+
# Apply full translation and summarization based on 'Published' column
|
34 |
+
data['Full Summary'] = data.apply(
|
35 |
+
lambda row: translate_and_summarize(row['Description']) if pd.isna(row['Published']) else "", axis=1
|
36 |
)
|
37 |
+
# Apply first paragraph translation and summarization
|
38 |
+
data['First Paragraph Summary'] = data['Description'].apply(translate_and_summarize_first_paragraph)
|
39 |
# Display data in a table
|
40 |
+
st.write(data[['ID', 'Title', 'Full Summary', 'First Paragraph Summary']])
|
|
|
41 |
else:
|
42 |
st.error("Uploaded CSV does not contain required 'Description' and 'Published' columns.")
|
43 |
|