richardorama
commited on
Commit
β’
f1b2a26
1
Parent(s):
0262183
Update app.py
Browse files
app.py
CHANGED
@@ -9,25 +9,11 @@ import ast
|
|
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 |
-
# Default article text
|
13 |
-
# DEFAULT_ARTICLE = """ New York (CNN)When Liana Barrientos was 23 years old, she got married in Westchester County, New York.
|
14 |
-
# A year later, she got married again in Westchester County, but to a different man and without divorcing her first husband.
|
15 |
-
# Only 18 days after that marriage, she got hitched yet again. Then, Barrientos declared "I do" five more times, sometimes only within two weeks of each other.
|
16 |
-
# In 2010, she married once more, this time in the Bronx. In an application for a marriage license, she stated it was her "first and only" marriage.
|
17 |
-
# Barrientos, now 39, is facing two criminal counts of "offering a false instrument for filing in the first degree," referring to her false statements on the
|
18 |
-
# 2010 marriage license application, according to court documents.
|
19 |
-
# """
|
20 |
-
|
21 |
-
# DEFAULT_STATEMENT = ""
|
22 |
-
|
23 |
-
# # Create a text area for user input
|
24 |
-
# STATEMENT = st.sidebar.text_area('Enter Article (String)', DEFAULT_ARTICLE, height=150)
|
25 |
-
|
26 |
# Define the summarization function
|
27 |
def summarize(txt):
|
28 |
st.write('\n\n')
|
29 |
-
st.write(txt[:100]) # Display the first 100 characters of the article
|
30 |
-
st.write('--------------------------------------------------------------')
|
31 |
summary = summarizer(txt, max_length=500, min_length=30, do_sample=False)
|
32 |
st.write(summary[0]['summary_text'])
|
33 |
|
@@ -45,12 +31,6 @@ else:
|
|
45 |
st.sidebar.button('Summarize Statement', disabled=True)
|
46 |
st.warning('π Please enter Statement!')
|
47 |
|
48 |
-
# # Create a button and trigger the summarize function when clicked
|
49 |
-
# if st.sidebar.button('Summarize Article'):
|
50 |
-
# summarize(ARTICLE)
|
51 |
-
# else:
|
52 |
-
# st.warning('π Please enter Article!')
|
53 |
-
|
54 |
|
55 |
|
56 |
#################################
|
@@ -60,16 +40,6 @@ else:
|
|
60 |
# No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
|
61 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
62 |
|
63 |
-
# Default article text
|
64 |
-
# DEFAULT_SENTIMENT = """[
|
65 |
-
# "I'm so happy today!",
|
66 |
-
# "This is the worst experience ever.",
|
67 |
-
# "It's a decent product, nothing special."
|
68 |
-
# ]"""
|
69 |
-
|
70 |
-
# DEFAULT_SENTIMENT = "I'm so happy today!"
|
71 |
-
|
72 |
-
|
73 |
def is_valid_list_string(string):
|
74 |
try:
|
75 |
result = ast.literal_eval(string)
|
@@ -82,11 +52,9 @@ def analyze(txt):
|
|
82 |
|
83 |
st.write('\n\n')
|
84 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
85 |
-
st.write('--------------------------------------------------------------')
|
86 |
|
87 |
# Display the results
|
88 |
-
#if type(txt_converted) == 'list':
|
89 |
-
#if isinstance(txt_converted, list):
|
90 |
if is_valid_list_string(txt):
|
91 |
txt_converted = ast.literal_eval(txt) #convert string to actual content, e.g. list
|
92 |
# Perform Hugging sentiment analysis on multiple texts
|
@@ -108,19 +76,7 @@ SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)',
|
|
108 |
# Enable the button only if there is text in the SENTIMENT variable
|
109 |
if SENTIMENT:
|
110 |
if st.sidebar.button('Analyze Sentiment'):
|
111 |
-
# Call your Analyze function here
|
112 |
-
#st.write(f"Summarizing: {SENTIMENT}")
|
113 |
analyze(SENTIMENT) # Directly pass the SENTIMENT
|
114 |
else:
|
115 |
st.sidebar.button('Summarize Sentiment', disabled=True)
|
116 |
st.warning('π Please enter Sentiment!')
|
117 |
-
|
118 |
-
# # Create a button and trigger the summarize function when clicked
|
119 |
-
# if st.sidebar.button('Summarize Sentiment'):
|
120 |
-
# #ast.literal_eval() is a function in Python that safely evaluates a string containing a valid Python expression,
|
121 |
-
# #such as lists, dictionaries, tuples, sets, integers, and floats. It parses the string and returns the corresponding
|
122 |
-
# #Python object, without executing any arbitrary code, which makes it safer than using eval().
|
123 |
-
# #summarize(str(SENTIMENT)) #explicitly change SENTIMENT to string so that even when ypu provide unquoted string, it still works
|
124 |
-
# analyze(SENTIMENT) # Directly pass the SENTIMENT
|
125 |
-
# else:
|
126 |
-
# st.warning('π Please enter Sentiment!')
|
|
|
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 summarize(txt):
|
14 |
st.write('\n\n')
|
15 |
+
#st.write(txt[:100]) # Display the first 100 characters of the article
|
16 |
+
#st.write('--------------------------------------------------------------')
|
17 |
summary = summarizer(txt, max_length=500, min_length=30, do_sample=False)
|
18 |
st.write(summary[0]['summary_text'])
|
19 |
|
|
|
31 |
st.sidebar.button('Summarize Statement', disabled=True)
|
32 |
st.warning('π Please enter Statement!')
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
|
36 |
#################################
|
|
|
40 |
# No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
|
41 |
sentiment_pipeline = pipeline("sentiment-analysis")
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
def is_valid_list_string(string):
|
44 |
try:
|
45 |
result = ast.literal_eval(string)
|
|
|
52 |
|
53 |
st.write('\n\n')
|
54 |
#st.write(txt[:100]) # Display the first 100 characters of the article
|
55 |
+
#st.write('--------------------------------------------------------------')
|
56 |
|
57 |
# Display the results
|
|
|
|
|
58 |
if is_valid_list_string(txt):
|
59 |
txt_converted = ast.literal_eval(txt) #convert string to actual content, e.g. list
|
60 |
# Perform Hugging sentiment analysis on multiple texts
|
|
|
76 |
# Enable the button only if there is text in the SENTIMENT variable
|
77 |
if SENTIMENT:
|
78 |
if st.sidebar.button('Analyze Sentiment'):
|
|
|
|
|
79 |
analyze(SENTIMENT) # Directly pass the SENTIMENT
|
80 |
else:
|
81 |
st.sidebar.button('Summarize Sentiment', disabled=True)
|
82 |
st.warning('π Please enter Sentiment!')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|