richardorama
commited on
Commit
β’
9a96f1a
1
Parent(s):
f79a195
Update app.py
Browse files
app.py
CHANGED
@@ -14,7 +14,7 @@ st.markdown("<h3 style='text-align: center; font-size: 16px;'>Simply Assorted La
|
|
14 |
st.markdown("<h3 style='text-align: center; font-size: 20px; color: blue;'>Orama's AI Craze</h3>", unsafe_allow_html=True)
|
15 |
|
16 |
|
17 |
-
################ SENTIMENT ANALYSIS - side bar #################
|
18 |
|
19 |
# Initialize the sentiment analysis pipeline
|
20 |
# No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
|
@@ -48,7 +48,7 @@ def analyze_sentiment(txt):
|
|
48 |
st.sidebar.write(f"Text: {txt}")
|
49 |
st.sidebar.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
|
50 |
|
51 |
-
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Sentiment Analysis</h3>", unsafe_allow_html=True)
|
52 |
DEFAULT_SENTIMENT = ""
|
53 |
# Create a text area for user input
|
54 |
SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)', DEFAULT_SENTIMENT, height=150)
|
@@ -62,52 +62,14 @@ else:
|
|
62 |
#st.warning('π Please enter Sentiment!')
|
63 |
|
64 |
|
65 |
-
|
66 |
-
################ STATEMENT SUMMARIZATION - main area #################
|
67 |
-
|
68 |
-
|
69 |
-
import streamlit as st
|
70 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
71 |
-
|
72 |
-
# Load the summarization model and tokenizer
|
73 |
-
MODEL_NAME = "facebook/bart-large-cnn" # A commonly used summarization model
|
74 |
-
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
75 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
76 |
-
|
77 |
-
# Streamlit UI for input
|
78 |
-
st.markdown("<h3 style='text-align: center; font-size: 20px; background-color: white; color: black;'>Text Summarization with BART</h3>", unsafe_allow_html=True)
|
79 |
-
|
80 |
-
# Input text area for the article
|
81 |
-
article = st.text_area("Enter text to summarize", height=300)
|
82 |
-
|
83 |
-
# Summarize button
|
84 |
-
if st.button("Summarize"):
|
85 |
-
if article:
|
86 |
-
# Tokenize input article
|
87 |
-
inputs = tokenizer(article, return_tensors="pt", truncation=True, padding="longest", max_length=1024)
|
88 |
-
|
89 |
-
# Generate summary
|
90 |
-
summary_ids = model.generate(inputs["input_ids"], max_length=150, min_length=30, length_penalty=2.0, num_beams=4, early_stopping=True)
|
91 |
-
|
92 |
-
# Decode summary
|
93 |
-
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
|
94 |
-
|
95 |
-
# Display the summary
|
96 |
-
st.write("**Summary:**")
|
97 |
-
st.write(summary)
|
98 |
-
else:
|
99 |
-
pass
|
100 |
-
#st.warning("Please enter some text to summarize!")
|
101 |
-
|
102 |
-
|
103 |
-
################ STATEMENT SUMMARIZATION1 - side bar #################
|
104 |
|
105 |
# Load the summarization model and tokenizer
|
106 |
MODEL_NAME = "facebook/bart-large-cnn" # A commonly used summarization model
|
107 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
108 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
109 |
|
110 |
-
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Text Summarization - BART</h3>", unsafe_allow_html=True)
|
111 |
DEFAULT_STATEMENT = ""
|
112 |
# Create a text area for user input
|
113 |
STATEMENT = st.sidebar.text_area('Enter Statement (String1)', DEFAULT_STATEMENT, height=150)
|
@@ -135,21 +97,13 @@ else:
|
|
135 |
#st.warning('π Please enter Statement!')
|
136 |
|
137 |
|
138 |
-
################ STATEMENT SUMMARIZATION - side bar #################
|
139 |
|
140 |
# Load the summarization model
|
141 |
#summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # smaller version of the model
|
142 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
143 |
|
144 |
-
|
145 |
-
# def summarize_statement(txt):
|
146 |
-
# st.write('\n\n')
|
147 |
-
# #st.write(txt[:100]) # Display the first 100 characters of the article
|
148 |
-
# #st.write('--------------------------------------------------------------')
|
149 |
-
# summary = summarizer(txt, max_length=500, min_length=30, do_sample=False)
|
150 |
-
# st.write(summary[0]['summary_text'])
|
151 |
-
|
152 |
-
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Text Summarization - BART</h3>", unsafe_allow_html=True)
|
153 |
DEFAULT_STATEMENT = ""
|
154 |
# Create a text area for user input
|
155 |
STATEMENT = st.sidebar.text_area('Enter Statement (String)', DEFAULT_STATEMENT, height=150)
|
|
|
14 |
st.markdown("<h3 style='text-align: center; font-size: 20px; color: blue;'>Orama's AI Craze</h3>", unsafe_allow_html=True)
|
15 |
|
16 |
|
17 |
+
################ SENTIMENT ANALYSIS - side bar - pippeline #################
|
18 |
|
19 |
# Initialize the sentiment analysis pipeline
|
20 |
# No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english
|
|
|
48 |
st.sidebar.write(f"Text: {txt}")
|
49 |
st.sidebar.write(f"Sentiment: {results[0]['label']}, Score: {results[0]['score']:.2f}\n")
|
50 |
|
51 |
+
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Sentiment Analysis - Pipeline</h3>", unsafe_allow_html=True)
|
52 |
DEFAULT_SENTIMENT = ""
|
53 |
# Create a text area for user input
|
54 |
SENTIMENT = st.sidebar.text_area('Enter Sentiment (String or List of Strings)', DEFAULT_SENTIMENT, height=150)
|
|
|
62 |
#st.warning('π Please enter Sentiment!')
|
63 |
|
64 |
|
65 |
+
################ STATEMENT SUMMARIZATION1 - side bar - tokenizer #################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
# Load the summarization model and tokenizer
|
68 |
MODEL_NAME = "facebook/bart-large-cnn" # A commonly used summarization model
|
69 |
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
|
70 |
model = AutoModelForSeq2SeqLM.from_pretrained(MODEL_NAME)
|
71 |
|
72 |
+
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Text Summarization - BART Tokenizer</h3>", unsafe_allow_html=True)
|
73 |
DEFAULT_STATEMENT = ""
|
74 |
# Create a text area for user input
|
75 |
STATEMENT = st.sidebar.text_area('Enter Statement (String1)', DEFAULT_STATEMENT, height=150)
|
|
|
97 |
#st.warning('π Please enter Statement!')
|
98 |
|
99 |
|
100 |
+
################ STATEMENT SUMMARIZATION - side bar - pipeline #################
|
101 |
|
102 |
# Load the summarization model
|
103 |
#summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6") # smaller version of the model
|
104 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
105 |
|
106 |
+
st.sidebar.markdown("<h3 style='text-align: center; font-size: 16px; background-color: white; color: black;'>Text Summarization - BART Pipeline</h3>", unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
DEFAULT_STATEMENT = ""
|
108 |
# Create a text area for user input
|
109 |
STATEMENT = st.sidebar.text_area('Enter Statement (String)', DEFAULT_STATEMENT, height=150)
|