- updates for webm generation
Browse files
app.py
CHANGED
@@ -5,76 +5,58 @@ import streamlit as st
|
|
5 |
from transformers import pipeline
|
6 |
from constants import tweet_generator_prompt, absa_prompt
|
7 |
|
8 |
-
# Initialize the model and tokenizer once, to avoid reloading them on each user interaction
|
9 |
-
# @st.cache_resource
|
10 |
-
# def load_model():
|
11 |
-
# start = time.time()
|
12 |
-
# classification_pipe = pipeline(
|
13 |
-
# "text-classification", model="tweetpie/toxic-content-detector", top_k=None)
|
14 |
-
# print(f"Time to load the classification model: {time.time() - start:.2f}s")
|
15 |
-
# start = time.time()
|
16 |
-
# absa_pipe = pipeline("text2text-generation", model="tweetpie/stance-aware-absa")
|
17 |
-
# print(f"Time to load the absa model: {time.time() - start:.2f}s")
|
18 |
-
# start = time.time()
|
19 |
-
# tweet_generation_pipe = pipeline("text2text-generation", model="tweetpie/stance-directed-tweet-generator")
|
20 |
-
# print(f"Time to load the tweet generation model: {time.time() - start:.2f}s")
|
21 |
-
# return classification_pipe, absa_pipe, tweet_generation_pipe
|
22 |
-
|
23 |
# Set up the title
|
24 |
st.title("Towards a Programmable Humanizing AI through Scalable Stance-Directed Architecture Dashboard")
|
25 |
|
26 |
-
#
|
27 |
-
|
28 |
-
"Select an ideology",
|
29 |
-
options=['Left', 'Right'],
|
30 |
-
index=0 # Default selection
|
31 |
-
)
|
32 |
-
|
33 |
-
# Layout for entities and aspects inputs
|
34 |
-
col1, col2, col3 = st.columns(3) # Adjusted to include a third column
|
35 |
|
|
|
|
|
36 |
with col1:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
st.header("Entities")
|
38 |
pro_entities = st.text_input("Pro Entities", help="Enter pro entities separated by commas")
|
39 |
anti_entities = st.text_input("Anti Entities", help="Enter anti entities separated by commas")
|
40 |
neutral_entities = st.text_input("Neutral Entities", help="Enter neutral entities separated by commas")
|
41 |
|
42 |
-
|
|
|
|
|
43 |
st.header("Aspects")
|
44 |
pro_aspects = st.text_input("Pro Aspects", help="Enter pro aspects separated by commas")
|
45 |
anti_aspects = st.text_input("Anti Aspects", help="Enter anti aspects separated by commas")
|
46 |
neutral_aspects = st.text_input("Neutral Aspects", help="Enter neutral aspects separated by commas")
|
47 |
|
48 |
-
# Generate button
|
49 |
generate_button = st.button("Generate tweet and classify toxicity")
|
50 |
|
51 |
-
# Load the model
|
52 |
# classifier, absa, generator = load_model()
|
53 |
|
54 |
# Process the input text and generate output
|
55 |
if generate_button:
|
56 |
-
with
|
57 |
with st.spinner('Generating the tweet...'):
|
58 |
-
#
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
anti_entities=anti_entities,
|
63 |
-
neutral_entities=neutral_entities,
|
64 |
-
pro_aspects=pro_aspects,
|
65 |
-
anti_aspects=anti_aspects,
|
66 |
-
neutral_aspects=neutral_aspects
|
67 |
-
)
|
68 |
-
time.sleep(5)
|
69 |
-
generated_tweet = [{"generated_text": "the agricultural sector is the single biggest recipient of migrants workers rights groups argue . nearly 90 % of those who come to the us are denied employment due to discriminatory employment laws and safety standards ."}]
|
70 |
|
71 |
# Displaying the input and model's output
|
72 |
st.write(f"Generated Tweet: {generated_tweet[0]['generated_text']}")
|
73 |
|
74 |
with st.spinner('Generating the Stance-Aware ABSA output...'):
|
75 |
-
time.sleep(3)
|
76 |
absa_output = [{'generated_text': 'migrants:positive, rights:positive, laws:positive, safety:positive'}]
|
77 |
-
|
78 |
stances = [x.strip() for x in absa_output[0]['generated_text'].split(',')]
|
79 |
stances = [{
|
80 |
'Aspect': x.split(':')[0],
|
@@ -86,15 +68,15 @@ if generate_button:
|
|
86 |
st.table(stances_df)
|
87 |
|
88 |
with st.spinner('Classifying the toxicity...'):
|
89 |
-
#
|
90 |
-
|
91 |
-
|
92 |
output = model_output[0]
|
93 |
|
94 |
st.write("Toxicity Classifier Output:")
|
95 |
-
for i in range(
|
96 |
if output[i]['label'] == 'LABEL_0':
|
97 |
-
st.write(f"Non-Toxic Content: {output[i]['score']*100:.1f}%")
|
98 |
elif output[i]['label'] == 'LABEL_1':
|
99 |
st.write(f"Toxic Content: {output[i]['score'] * 100:.1f}%")
|
100 |
else:
|
|
|
5 |
from transformers import pipeline
|
6 |
from constants import tweet_generator_prompt, absa_prompt
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
# Set up the title
|
9 |
st.title("Towards a Programmable Humanizing AI through Scalable Stance-Directed Architecture Dashboard")
|
10 |
|
11 |
+
# Adjust the layout for wider containers
|
12 |
+
st.set_page_config(layout="wide")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
+
# Container for ideology selection spanning across first two columns
|
15 |
+
col1, col2, _ = st.columns([2, 2, 4]) # Adjust the ratios as needed for better appearance
|
16 |
with col1:
|
17 |
+
model_selection = st.selectbox(
|
18 |
+
"Select an ideology",
|
19 |
+
options=['Left', 'Right'],
|
20 |
+
index=0 # Default selection
|
21 |
+
)
|
22 |
+
|
23 |
+
# Layout for entities and aspects inputs
|
24 |
+
with col2:
|
25 |
st.header("Entities")
|
26 |
pro_entities = st.text_input("Pro Entities", help="Enter pro entities separated by commas")
|
27 |
anti_entities = st.text_input("Anti Entities", help="Enter anti entities separated by commas")
|
28 |
neutral_entities = st.text_input("Neutral Entities", help="Enter neutral entities separated by commas")
|
29 |
|
30 |
+
col3, col4 = st.columns([1, 3]) # Splitting the remaining space for aspects input and outputs
|
31 |
+
|
32 |
+
with col3:
|
33 |
st.header("Aspects")
|
34 |
pro_aspects = st.text_input("Pro Aspects", help="Enter pro aspects separated by commas")
|
35 |
anti_aspects = st.text_input("Anti Aspects", help="Enter anti aspects separated by commas")
|
36 |
neutral_aspects = st.text_input("Neutral Aspects", help="Enter neutral aspects separated by commas")
|
37 |
|
38 |
+
# Generate button (placed outside the columns so it spans the full width)
|
39 |
generate_button = st.button("Generate tweet and classify toxicity")
|
40 |
|
41 |
+
# Load the model (commented out, assuming model loading is handled elsewhere)
|
42 |
# classifier, absa, generator = load_model()
|
43 |
|
44 |
# Process the input text and generate output
|
45 |
if generate_button:
|
46 |
+
with col4: # This block is for displaying outputs in the wider column
|
47 |
with st.spinner('Generating the tweet...'):
|
48 |
+
# Example placeholders for the generated outputs
|
49 |
+
time.sleep(5) # Simulating delay
|
50 |
+
generated_tweet = [{
|
51 |
+
"generated_text": "the agricultural sector is the single biggest recipient of migrants workers rights groups argue . nearly 90 % of those who come to the us are denied employment due to discriminatory employment laws and safety standards ."}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
# Displaying the input and model's output
|
54 |
st.write(f"Generated Tweet: {generated_tweet[0]['generated_text']}")
|
55 |
|
56 |
with st.spinner('Generating the Stance-Aware ABSA output...'):
|
57 |
+
time.sleep(3) # Simulating delay
|
58 |
absa_output = [{'generated_text': 'migrants:positive, rights:positive, laws:positive, safety:positive'}]
|
59 |
+
|
60 |
stances = [x.strip() for x in absa_output[0]['generated_text'].split(',')]
|
61 |
stances = [{
|
62 |
'Aspect': x.split(':')[0],
|
|
|
68 |
st.table(stances_df)
|
69 |
|
70 |
with st.spinner('Classifying the toxicity...'):
|
71 |
+
time.sleep(2) # Simulating delay
|
72 |
+
model_output = [[{'label': 'LABEL_0', 'score': 0.9999998807907104},
|
73 |
+
{'label': 'LABEL_1', 'score': 1.1919785395889282e-07}]]
|
74 |
output = model_output[0]
|
75 |
|
76 |
st.write("Toxicity Classifier Output:")
|
77 |
+
for i in range(len(output)):
|
78 |
if output[i]['label'] == 'LABEL_0':
|
79 |
+
st.write(f"Non-Toxic Content: {output[i]['score'] * 100:.1f}%")
|
80 |
elif output[i]['label'] == 'LABEL_1':
|
81 |
st.write(f"Toxic Content: {output[i]['score'] * 100:.1f}%")
|
82 |
else:
|