richardorama
commited on
Commit
β’
ec929e1
1
Parent(s):
f1b2a26
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,6 @@
|
|
|
|
|
|
|
|
1 |
#x = st.slider('Select a value')
|
2 |
#st.write(x, 'squared is', x * x)
|
3 |
|
@@ -5,12 +8,15 @@ import streamlit as st
|
|
5 |
from transformers import pipeline
|
6 |
import ast
|
7 |
|
|
|
|
|
|
|
8 |
# Load the summarization model
|
9 |
#summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # smaller version of the model
|
10 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
11 |
|
12 |
# Define the summarization function
|
13 |
-
def
|
14 |
st.write('\n\n')
|
15 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
16 |
#st.write('--------------------------------------------------------------')
|
@@ -25,16 +31,13 @@ STATEMENT = st.sidebar.text_area('Enter Statement (String)', DEFAULT_STATEMENT,
|
|
25 |
if STATEMENT:
|
26 |
if st.sidebar.button('Summarize Statement'):
|
27 |
# Call your Summarize function here
|
28 |
-
#
|
29 |
-
summarize(STATEMENT) # Directly pass the STATEMENT
|
30 |
else:
|
31 |
st.sidebar.button('Summarize Statement', disabled=True)
|
32 |
st.warning('π Please enter Statement!')
|
33 |
|
34 |
|
35 |
-
|
36 |
-
#################################
|
37 |
-
|
38 |
|
39 |
# Initialize the sentiment analysis pipeline
|
40 |
# No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
|
@@ -48,7 +51,7 @@ def is_valid_list_string(string):
|
|
48 |
return False
|
49 |
|
50 |
# Define the summarization function
|
51 |
-
def
|
52 |
|
53 |
st.write('\n\n')
|
54 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
@@ -76,7 +79,7 @@ SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)',
|
|
76 |
# Enable the button only if there is text in the SENTIMENT variable
|
77 |
if SENTIMENT:
|
78 |
if st.sidebar.button('Analyze Sentiment'):
|
79 |
-
|
80 |
else:
|
81 |
-
st.sidebar.button('
|
82 |
st.warning('π Please enter Sentiment!')
|
|
|
1 |
+
# Natural Language Tools
|
2 |
+
# Richard Orama - September 2024
|
3 |
+
|
4 |
#x = st.slider('Select a value')
|
5 |
#st.write(x, 'squared is', x * x)
|
6 |
|
|
|
8 |
from transformers import pipeline
|
9 |
import ast
|
10 |
|
11 |
+
|
12 |
+
################ STATEMENT SUMMARIZATION #################
|
13 |
+
|
14 |
# Load the summarization model
|
15 |
#summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # smaller version of the model
|
16 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
17 |
|
18 |
# Define the summarization function
|
19 |
+
def summarize_statement(txt):
|
20 |
st.write('\n\n')
|
21 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
22 |
#st.write('--------------------------------------------------------------')
|
|
|
31 |
if STATEMENT:
|
32 |
if st.sidebar.button('Summarize Statement'):
|
33 |
# Call your Summarize function here
|
34 |
+
summarize_statement(STATEMENT) # Directly pass the STATEMENT
|
|
|
35 |
else:
|
36 |
st.sidebar.button('Summarize Statement', disabled=True)
|
37 |
st.warning('π Please enter Statement!')
|
38 |
|
39 |
|
40 |
+
################ SENTIMENT ANALYSIS #################
|
|
|
|
|
41 |
|
42 |
# Initialize the sentiment analysis pipeline
|
43 |
# No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
|
|
|
51 |
return False
|
52 |
|
53 |
# Define the summarization function
|
54 |
+
def analyze_sentiment(txt):
|
55 |
|
56 |
st.write('\n\n')
|
57 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
|
|
79 |
# Enable the button only if there is text in the SENTIMENT variable
|
80 |
if SENTIMENT:
|
81 |
if st.sidebar.button('Analyze Sentiment'):
|
82 |
+
analyze_sentiment(SENTIMENT) # Directly pass the SENTIMENT
|
83 |
else:
|
84 |
+
st.sidebar.button('Analyze Sentiment', disabled=True)
|
85 |
st.warning('π Please enter Sentiment!')
|