Spaces:
Sleeping
Sleeping
import streamlit as st | |
from transformers import pipeline | |
from transformers import T5ForConditionalGeneration, T5Tokenizer | |
def tras_sum(input): | |
model_name = 'utrobinmv/t5_summary_en_ru_zh_base_2048' | |
model = T5ForConditionalGeneration.from_pretrained(model_name) | |
tokenizer = T5Tokenizer.from_pretrained(model_name) | |
# text summary generate | |
prefix = 'summary to en: ' | |
src_text = prefix + input | |
input_ids = tokenizer(src_text, return_tensors="pt") | |
generated_tokens = model.generate(**input_ids) | |
traslated_summary = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True) | |
return traslated_summary | |
# Load the summarization & translation model pipeline | |
sentiment_pipeline = pipeline("text-classification", model='Howosn/Sentiment_Model',return_all_scores=True) | |
# Streamlit application title | |
st.title("Emotion analysis") | |
st.write("Turn Your Input Into Sentiment Score") | |
# Text input for the user to enter the text to analyze | |
text = st.text_area("Enter the text", "") | |
# Perform analysis result when the user clicks the "Analyse" button | |
if st.button("Analyse"): | |
# Perform text classification on the input text | |
trans = tras_sum(text)[0] | |
results = sentiment_pipeline(trans)[0] | |
# Display the classification result | |
max_score = float('-inf') | |
max_label = '' | |
for result in results: | |
if result['score'] > max_score: | |
max_score = result['score'] | |
max_label = result['label'] | |
st.write("Text:", trans) | |
st.write("Label:", max_label) | |
st.write("Score:", max_score) |