Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Intro to Ai Sentiment Analysis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
joshmk31
Intro to Ai Sentiment Analysis
Commits
9524344d
Commit
9524344d
authored
1 year ago
by
Sid Pothineni
Browse files
Options
Downloads
Patches
Plain Diff
made the ui nicer
parent
e7e6b434
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ui.py
+52
-23
52 additions, 23 deletions
ui.py
with
52 additions
and
23 deletions
ui.py
+
52
−
23
View file @
9524344d
# Received a lot of assistance from: https://realpython.com/python-gui-tkinter/
import
tkinter
as
tk
import
tkinter
as
tk
from
tkinter
import
ttk
from
transformers
import
pipeline
from
transformers
import
pipeline
sentiment_analysis_model
=
"
lxyuan/distilbert-base-multilingual-cased-sentiments-student
"
sentiment_analysis_model
=
"
lxyuan/distilbert-base-multilingual-cased-sentiments-student
"
sentiment_analyzer
=
pipeline
(
"
sentiment-analysis
"
,
model
=
sentiment_analysis_model
)
sentiment_analyzer
=
pipeline
(
"
sentiment-analysis
"
,
model
=
sentiment_analysis_model
)
def
submit_for_analysis
():
def
submit_for_analysis
():
input
=
text_entry
.
get
(
"
1.0
"
,
tk
.
END
)
input_text
=
text_entry
.
get
(
"
1.0
"
,
tk
.
END
)
try
:
res
=
sentiment_analyzer
(
input_text
)
# Assuming 'res' is a list of dictionaries, we take the first result
label
=
res
[
0
][
'
label
'
].
capitalize
()
# Capitalize the label
score
=
round
(
res
[
0
][
'
score
'
],
3
)
# Round the score to 3 decimal places
# Update the result label with a more user-friendly format
result_text
.
set
(
f
"
Result:
{
label
}
statement
\n
Statement
'
s score:
{
score
}
"
)
# Change the background color based on the sentiment
color
=
"
#FFCCCC
"
if
label
.
lower
()
==
"
negative
"
else
"
#CCFFCC
"
result_label
.
config
(
background
=
color
)
except
Exception
as
e
:
messagebox
.
showerror
(
"
Error
"
,
str
(
e
))
result_text
.
set
(
""
)
# Analyze input with emotional intent
# Create the main window
window
=
tk
.
Tk
()
res
=
sentiment_analyzer
(
input
)
window
.
geometry
(
"
700x800
"
)
print
(
res
)
window
.
title
(
"
Sentiment Analyzer
"
)
# if would be received negatively, suggest less controversial alternative
# Styling
style
=
ttk
.
Style
()
style
.
theme_use
(
'
clam
'
)
# Use a website classification to tell the user where their post would likely fit the best
# Header Frame
print
(
"
User entered:
"
,
input
)
header_frame
=
ttk
.
Frame
(
window
,
padding
=
"
10
"
)
header_frame
.
pack
(
fill
=
'
x
'
)
# Create the window
header_label
=
ttk
.
Label
(
header_frame
,
text
=
"
Sentiment Analyzer
"
,
font
=
(
"
Helvetica
"
,
16
))
window
=
tk
.
Tk
()
header_label
.
pack
()
window
.
geometry
(
"
600x600
"
)
header
=
tk
.
Label
(
text
=
"
Sentiment Analyzer
"
)
# Text Entry Frame
header
.
pack
()
text_frame
=
ttk
.
Frame
(
window
,
padding
=
"
10
"
)
text_frame
.
pack
(
fill
=
'
x
'
)
text_entry
=
tk
.
Text
(
text_frame
,
width
=
80
,
height
=
10
)
text_entry
.
pack
(
padx
=
5
,
pady
=
5
)
# Buttons Frame
buttons_frame
=
ttk
.
Frame
(
window
,
padding
=
"
10
"
)
buttons_frame
.
pack
(
fill
=
'
x
'
)
analyze_button
=
ttk
.
Button
(
buttons_frame
,
text
=
"
Analyze
"
,
command
=
submit_for_analysis
)
analyze_button
.
pack
(
side
=
'
left
'
,
padx
=
5
)
exit_button
=
ttk
.
Button
(
buttons_frame
,
text
=
"
Exit
"
,
command
=
window
.
quit
)
exit_button
.
pack
(
side
=
'
right
'
,
padx
=
5
)
#
Creates text box for user to input their post they wish to analyz
e
#
Result Fram
e
text_entry
=
tk
.
Text
(
window
,
width
=
"
70
"
,
height
=
"
7
"
)
result_frame
=
t
tk
.
Frame
(
window
,
padding
=
"
10
"
)
text_entry
.
pack
(
)
result_frame
.
pack
(
fill
=
'
both
'
,
expand
=
True
)
# Analyze button, calls the submit_for_analysis
result_text
=
tk
.
StringVar
()
analyze_button
=
tk
.
Button
(
window
,
text
=
"
Analyze
"
,
width
=
"
7
"
,
height
=
"
2
"
,
command
=
submit_for_analysis
)
result_label
=
t
tk
.
Label
(
result_frame
,
textvariable
=
result_text
,
font
=
(
"
Helvetica
"
,
12
),
background
=
"
#DDDDDD
"
,
wraplength
=
500
)
analyze_button
.
pack
(
)
result_label
.
pack
(
padx
=
5
,
pady
=
5
,
fill
=
'
both
'
)
window
.
mainloop
()
window
.
mainloop
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment