File size: 2,041 Bytes
88c381a
 
91dd84e
240b689
553472c
ec5e298
19dc535
 
0f375b6
 
19dc535
63b60f3
0f375b6
 
 
 
 
 
 
 
19dc535
88c381a
e2f5e33
0f375b6
19dc535
 
 
 
 
 
793fb2e
 
0f375b6
 
 
793fb2e
0f375b6
 
19dc535
0f375b6
88c381a
793fb2e
225ca46
88c381a
63b60f3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import streamlit as st
import pandas as pd
from transformers import pipeline

# Load translation and summarization pipelines
translator = pipeline("translation_ru_to_en", model="Helsinki-NLP/opus-mt-ru-en")
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")

# Function to translate and summarize text
def translate_and_summarize(text):
    translated_text = translator(text)[0]['translation_text']
    summary = 'News Alert. ' + summarizer(translated_text, max_length=140, min_length=110, do_sample=False)[0]['summary_text']
    return summary

# Function to translate and summarize first paragraph
def translate_and_summarize_first_paragraph(text):
    first_sentence = text.split('.')[0] + '.'
    translated_text = translator(first_sentence)[0]['translation_text']
    summary = summarizer(translated_text, max_length=20, min_length=5, do_sample=False)[0]['summary_text']
    return summary

# Streamlit interface
def main():
    st.title("CSV Translator and Summarizer")

    # File uploader
    uploaded_file = st.file_uploader("Choose a CSV file", type="csv")
    if uploaded_file is not None:
        # Read data
        data = pd.read_csv(uploaded_file)
        # Check if 'Description' and 'Published' columns exist
        if 'Description' in data.columns and 'Published' in data.columns:
            # Apply full translation and summarization based on 'Published' column
            data['Full Summary'] = data.apply(
                lambda row: translate_and_summarize(row['Description']) if pd.isna(row['Published']) else "", axis=1
            )
            # Apply first paragraph translation and summarization
            data['First Paragraph Summary'] = data['Description'].apply(translate_and_summarize_first_paragraph)
            # Display data in a table
            st.write(data[['ID', 'Title', 'Full Summary', 'First Paragraph Summary']])
        else:
            st.error("Uploaded CSV does not contain required 'Description' and 'Published' columns.")

if __name__ == "__main__":
    main()