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
c7cd6ab8
Commit
c7cd6ab8
authored
1 year ago
by
Sid Pothineni
Browse files
Options
Downloads
Patches
Plain Diff
added website category classification
parent
455a4b10
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
+35
-25
35 additions, 25 deletions
ui.py
with
35 additions
and
25 deletions
ui.py
+
35
−
25
View file @
c7cd6ab8
...
...
@@ -6,6 +6,9 @@ from transformers import pipeline
sentiment_analysis_model
=
"
lxyuan/distilbert-base-multilingual-cased-sentiments-student
"
sentiment_analyzer
=
pipeline
(
"
sentiment-analysis
"
,
model
=
sentiment_analysis_model
)
website_class_model
=
"
alimazhar-110/website_classification
"
website_class_analyzer
=
pipeline
(
"
text-classification
"
,
model
=
website_class_model
)
# History list to store past results
history
=
[]
...
...
@@ -13,22 +16,29 @@ def submit_for_analysis():
input_text
=
text_entry
.
get
(
"
1.0
"
,
tk
.
END
).
strip
()
if
input_text
:
try
:
res
=
sentiment_analyzer
(
input_text
)
label
=
res
[
0
][
'
label
'
].
capitalize
()
score
=
round
(
res
[
0
][
'
score
'
],
3
)
result_text
.
set
(
f
"
Result:
{
label
}
statement
\n
Statement
'
s score:
{
score
}
"
)
color
=
"
#FFCCCC
"
if
label
.
lower
()
==
"
negative
"
else
"
#CCFFCC
"
result_label
.
config
(
background
=
color
)
# Update history by appending new entries
history
.
append
((
input_text
,
label
,
score
))
# Update the history display
sentiment_result
=
sentiment_analyzer
(
input_text
)
website_result
=
website_class_analyzer
(
input_text
)
# Sentiment analysis results
sentiment_label
=
sentiment_result
[
0
][
"
label
"
].
capitalize
()
sentiment_score
=
round
(
sentiment_result
[
0
][
"
score
"
],
3
)
sentiment_color
=
"
#FFCCCC
"
if
sentiment_label
.
lower
()
==
"
negative
"
else
"
#CCFFCC
"
sentiment_result_text
.
set
(
f
"
Sentiment:
{
sentiment_label
}
statement
\n
Score:
{
sentiment_score
}
"
)
sentiment_result_label
.
config
(
background
=
sentiment_color
)
# Website classification results
website_type
=
website_result
[
0
][
"
label
"
]
website_confidence
=
round
(
website_result
[
0
][
"
score
"
],
3
)
website_results_text
.
set
(
f
"
Website Category:
{
website_type
}
\n
Confidence:
{
website_confidence
}
"
)
# Update history
history
.
append
((
input_text
,
sentiment_label
,
sentiment_score
,
website_type
,
website_confidence
))
update_history_display
()
except
Exception
as
e
:
messagebox
.
showerror
(
"
Error
"
,
str
(
e
))
result_text
.
set
(
""
)
sentiment_result_text
.
set
(
""
)
website_results_text
.
set
(
""
)
else
:
messagebox
.
showinfo
(
"
Info
"
,
"
Please enter some text to analyze.
"
)
...
...
@@ -36,14 +46,14 @@ def update_history_display():
history_text
.
config
(
state
=
tk
.
NORMAL
)
# Enable the widget before updating
history_text
.
delete
(
"
1.0
"
,
tk
.
END
)
# Clear the existing content
for
i
,
entry
in
enumerate
(
reversed
(
history
)):
input_text
,
label
,
scor
e
=
entry
history_text
.
insert
(
tk
.
END
,
f
"
{
i
+
1
}
.
\"
{
input_text
}
\"
-
{
label
}
(
{
scor
e
}
)
\n\n
"
)
input_text
,
sentiment_label
,
sentiment_score
,
website_type
,
website_confidenc
e
=
entry
history_text
.
insert
(
tk
.
END
,
f
"
{
i
+
1
}
.
\"
{
input_text
}
\"
-
Sentiment:
{
sentiment_label
}
(
{
sentiment_score
}
), Website Category:
{
website_type
}
(Confidence:
{
website_confidenc
e
}
)
\n\n
"
)
history_text
.
config
(
state
=
tk
.
DISABLED
)
# Disable the widget after updating
# Create the main window
window
=
tk
.
Tk
()
window
.
geometry
(
"
700x
9
00
"
)
#
Increas
ed height to accommodate
history a
re
a
window
.
title
(
"
Sentiment Analyzer
"
)
window
.
geometry
(
"
700x
10
00
"
)
#
Adjust
ed height to accommodate
additional featu
re
s
window
.
title
(
"
Sentiment
and Website Category
Analyzer
"
)
# Styling
style
=
ttk
.
Style
()
...
...
@@ -52,24 +62,20 @@ style.theme_use('clam')
# Header Frame
header_frame
=
ttk
.
Frame
(
window
,
padding
=
"
10
"
)
header_frame
.
pack
(
fill
=
'
x
'
)
header_label
=
ttk
.
Label
(
header_frame
,
text
=
"
Sentiment Analyzer
"
,
font
=
(
"
Helvetica
"
,
16
))
header_label
=
ttk
.
Label
(
header_frame
,
text
=
"
Sentiment and Website Category Analyzer
"
,
font
=
(
"
Helvetica
"
,
16
))
header_label
.
pack
()
# Text Entry Frame
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
)
...
...
@@ -77,9 +83,13 @@ exit_button.pack(side='right', padx=5)
result_frame
=
ttk
.
Frame
(
window
,
padding
=
"
10
"
)
result_frame
.
pack
(
fill
=
'
both
'
,
expand
=
True
)
result_text
=
tk
.
StringVar
()
result_label
=
ttk
.
Label
(
result_frame
,
textvariable
=
result_text
,
font
=
(
"
Helvetica
"
,
12
),
background
=
"
#DDDDDD
"
,
wraplength
=
500
)
result_label
.
pack
(
padx
=
5
,
pady
=
5
,
fill
=
'
both
'
)
sentiment_result_text
=
tk
.
StringVar
()
sentiment_result_label
=
ttk
.
Label
(
result_frame
,
textvariable
=
sentiment_result_text
,
font
=
(
"
Helvetica
"
,
12
),
background
=
"
#DDDDDD
"
,
wraplength
=
500
)
sentiment_result_label
.
pack
(
padx
=
5
,
pady
=
5
,
fill
=
'
both
'
)
website_results_text
=
tk
.
StringVar
()
website_results_label
=
ttk
.
Label
(
result_frame
,
textvariable
=
website_results_text
,
font
=
(
"
Helvetica
"
,
12
),
background
=
"
#DDDDDD
"
,
wraplength
=
500
)
website_results_label
.
pack
(
padx
=
5
,
pady
=
5
,
fill
=
'
both
'
)
# History Frame
history_frame
=
ttk
.
Frame
(
window
,
padding
=
"
10
"
)
...
...
@@ -95,4 +105,4 @@ history_text = tk.Text(history_frame, width=80, height=10, yscrollcommand=scroll
history_text
.
pack
(
side
=
'
left
'
,
padx
=
5
,
pady
=
5
,
fill
=
'
both
'
,
expand
=
True
)
scrollbar
.
config
(
command
=
history_text
.
yview
)
window
.
mainloop
()
\ No newline at end of file
window
.
mainloop
()
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