Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
import streamlit as st
|
3 |
import pandas as pd
|
|
|
4 |
|
5 |
# Load translation and summarization pipelines
|
6 |
translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
|
@@ -9,7 +9,7 @@ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
|
9 |
# Function to translate and summarize text
|
10 |
def translate_and_summarize(text):
|
11 |
translated_text = translator(text)[0]['translation_text']
|
12 |
-
summary = summarizer(translated_text, max_length=
|
13 |
return summary
|
14 |
|
15 |
# Streamlit interface
|
@@ -22,16 +22,23 @@ def main():
|
|
22 |
# Read data
|
23 |
data = pd.read_csv(uploaded_file)
|
24 |
|
25 |
-
# Check
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
|
|
|
|
|
|
|
|
|
|
|
33 |
else:
|
34 |
-
st.
|
35 |
|
36 |
if __name__ == "__main__":
|
37 |
main()
|
|
|
|
|
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")
|
|
|
9 |
# Function to translate and summarize text
|
10 |
def translate_and_summarize(text):
|
11 |
translated_text = translator(text)[0]['translation_text']
|
12 |
+
summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
|
13 |
return summary
|
14 |
|
15 |
# Streamlit interface
|
|
|
22 |
# Read data
|
23 |
data = pd.read_csv(uploaded_file)
|
24 |
|
25 |
+
# Check necessary columns
|
26 |
+
required_columns = {'Description', 'Published'}
|
27 |
+
if not required_columns.issubset(data.columns):
|
28 |
+
missing_cols = required_columns - set(data.columns)
|
29 |
+
st.error(f"Uploaded CSV is missing the following required column(s): {', '.join(missing_cols)}")
|
30 |
+
return
|
31 |
|
32 |
+
# Filter rows where 'Published' is unchecked (assuming False or equivalent)
|
33 |
+
data_filtered = data[data['Published'] == False]
|
34 |
|
35 |
+
# Apply translation and summarization
|
36 |
+
if not data_filtered.empty:
|
37 |
+
data_filtered['Summary'] = data_filtered['Description'].apply(translate_and_summarize)
|
38 |
+
# Display data in a table
|
39 |
+
st.write(data_filtered[['ID', 'Title', 'Summary']])
|
40 |
else:
|
41 |
+
st.write("No unpublished descriptions to process.")
|
42 |
|
43 |
if __name__ == "__main__":
|
44 |
main()
|