|
|
|
|
|
|
|
|
|
|
|
|
|
import streamlit as st |
|
from transformers import pipeline |
|
import ast |
|
|
|
|
|
|
|
|
|
|
|
|
|
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") |
|
|
|
|
|
def summarize_statement(txt): |
|
st.write('\n\n') |
|
|
|
|
|
summary = summarizer(txt, max_length=500, min_length=30, do_sample=False) |
|
st.write(summary[0]['summary_text']) |
|
|
|
DEFAULT_STATEMENT = "" |
|
|
|
STATEMENT = st.sidebar.text_area('Enter Statement (String)', DEFAULT_STATEMENT, height=150) |
|
|
|
|
|
if STATEMENT: |
|
if st.sidebar.button('Summarize Statement'): |
|
|
|
summarize_statement(STATEMENT) |
|
else: |
|
st.sidebar.button('Summarize Statement', disabled=True) |
|
st.warning('π Please enter Statement!') |
|
|
|
|
|
|
|
|
|
|
|
|
|
sentiment_pipeline = pipeline("sentiment-analysis") |
|
|
|
def is_valid_list_string(string): |
|
try: |
|
result = ast.literal_eval(string) |
|
return isinstance(result, list) |
|
except (ValueError, SyntaxError): |
|
return False |
|
|
|
|
|
def analyze_sentiment(txt): |
|
|
|
st.write('\n\n') |
|
|
|
|
|
|
|
|
|
if is_valid_list_string(txt): |
|
txt_converted = ast.literal_eval(txt) |
|
|
|
results = sentiment_pipeline(txt_converted) |
|
for i, text in enumerate(txt_converted): |
|
st.write(f"Text: {text}") |
|
st.write(f"Sentiment: {results[i]['label']}, Score: {results[i]['score']:.2f}\n") |
|
else: |
|
|
|
results = sentiment_pipeline(txt) |
|
st.write(f"Text: {txt}") |
|
st.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n") |
|
|
|
|
|
DEFAULT_SENTIMENT = "" |
|
|
|
SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)', DEFAULT_SENTIMENT, height=150) |
|
|
|
|
|
if SENTIMENT: |
|
if st.sidebar.button('Analyze Sentiment'): |
|
analyze_sentiment(SENTIMENT) |
|
else: |
|
st.sidebar.button('Analyze Sentiment', disabled=True) |
|
st.warning('π Please enter Sentiment!') |
|
|