Update app.py
Browse files
app.py
CHANGED
@@ -2,42 +2,48 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
from transformers import pipeline
|
4 |
|
5 |
-
#
|
6 |
translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
|
|
|
|
|
|
|
|
|
7 |
|
8 |
|
9 |
-
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
10 |
|
11 |
-
# Load your CSV file
|
12 |
-
@st.cache
|
13 |
-
def load_data(filepath):
|
14 |
-
return pd.read_csv(filepath)
|
15 |
|
16 |
-
# Translate and summarize text
|
17 |
def translate_and_summarize(text):
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
|
27 |
# Streamlit interface
|
28 |
def main():
|
29 |
-
st.title(
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
-
if file_path:
|
33 |
-
data = load_data(file_path)
|
34 |
if 'Description' in data.columns:
|
35 |
-
|
36 |
-
|
37 |
data['Summary'] = data['Description'].apply(translate_and_summarize)
|
38 |
-
|
|
|
|
|
|
|
39 |
else:
|
40 |
-
st.error("
|
41 |
|
42 |
if __name__ == "__main__":
|
43 |
main()
|
|
|
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 |
+
|
11 |
|
12 |
|
|
|
13 |
|
|
|
|
|
|
|
|
|
14 |
|
|
|
15 |
def translate_and_summarize(text):
|
16 |
+
translated_text = translator(text)[0]['translation_text']
|
17 |
+
summary = summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
|
18 |
+
return summary
|
19 |
+
|
20 |
+
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
|
25 |
# Streamlit interface
|
26 |
def main():
|
27 |
+
st.title("CSV Translator and Summarizer")
|
28 |
+
|
29 |
+
# File uploader
|
30 |
+
uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
|
31 |
+
if uploaded_file is not None:
|
32 |
+
# Read data
|
33 |
+
data = pd.read_csv(uploaded_file)
|
34 |
+
|
35 |
+
# Check if 'Description' column exists
|
36 |
|
|
|
|
|
37 |
if 'Description' in data.columns:
|
38 |
+
# Apply translation and summarization
|
39 |
+
|
40 |
data['Summary'] = data['Description'].apply(translate_and_summarize)
|
41 |
+
|
42 |
+
# Display data in a table
|
43 |
+
st.write(data[['ID', 'Title', 'Summary']])
|
44 |
+
|
45 |
else:
|
46 |
+
st.error("Uploaded CSV does not contain 'Description' column.")
|
47 |
|
48 |
if __name__ == "__main__":
|
49 |
main()
|