youtube / app.py
Fralet's picture
Update app.py
19dc535 verified
raw
history blame
1.27 kB
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 = summarizer(translated_text, max_length=140, min_length=110, 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' column exists
if 'Description' in data.columns:
# Apply translation and summarization
data['Summary'] = data['Description'].apply(translate_and_summarize)
# Display data in a table
st.write(data[['ID', 'Title', 'Summary']])
else:
st.error("Uploaded CSV does not contain 'Description' column.")
if __name__ == "__main__":
main()