Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
chatbot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
option3a
chatbot
Commits
a6440706
Commit
a6440706
authored
Jan 30, 2024
by
Tiravy Amaury
Browse files
Options
Downloads
Patches
Plain Diff
commentaires
parent
d215ad7a
No related branches found
No related tags found
1 merge request
!6
Test amau
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
chatbot_complet.py
+8
-6
8 additions, 6 deletions
chatbot_complet.py
with
8 additions
and
6 deletions
chatbot_complet.py
+
8
−
6
View file @
a6440706
...
@@ -23,14 +23,14 @@ def extract_keywords_textblob_french(sentence):
...
@@ -23,14 +23,14 @@ def extract_keywords_textblob_french(sentence):
return
'
'
.
join
(
keywords
)
return
'
'
.
join
(
keywords
)
def
create_vectorial_base
(
text_lines
,
min_chars
=
5
0
):
def
create_vectorial_base
(
text_lines
,
min_chars
=
1
0
):
filtered_lines
=
[
line
for
line
in
text_lines
if
len
(
line
)
>=
min_chars
]
filtered_lines
=
[
line
for
line
in
text_lines
if
len
(
line
)
>=
min_chars
]
if
not
filtered_lines
:
if
not
filtered_lines
:
print
(
"
No lines with at least
5
0 characters found.
"
)
print
(
"
No lines with at least
1
0 characters found.
"
)
return
None
,
None
,
None
return
None
,
None
,
None
vectorizer
=
TfidfVectorizer
()
vectorizer
=
TfidfVectorizer
()
#a tester en option : stop_words=list(stopwords.words('french'))
vectorial_base
=
vectorizer
.
fit_transform
(
filtered_lines
).
toarray
()
vectorial_base
=
vectorizer
.
fit_transform
(
filtered_lines
).
toarray
()
feature_names
=
vectorizer
.
get_feature_names_out
()
feature_names
=
vectorizer
.
get_feature_names_out
()
...
@@ -42,7 +42,7 @@ def get_best_answers(question, text_lines, vectorizer, vectorial_base):
...
@@ -42,7 +42,7 @@ def get_best_answers(question, text_lines, vectorizer, vectorial_base):
# Calculate cosine similarity between the question and each text line
# Calculate cosine similarity between the question and each text line
similarities
=
cosine_similarity
(
question_vector
,
vectorial_base
).
flatten
()
similarities
=
cosine_similarity
(
question_vector
,
vectorial_base
).
flatten
()
# Get the indices of the top
5
most similar text lines
# Get the indices of the top
3
most similar text lines
top_indices
=
np
.
argsort
(
similarities
)[
-
3
:][::
-
1
]
top_indices
=
np
.
argsort
(
similarities
)[
-
3
:][::
-
1
]
# Retrieve the corresponding text lines
# Retrieve the corresponding text lines
best_answers
=
[
text_lines
[
i
]
+
"
\n
"
for
i
in
top_indices
]
best_answers
=
[
text_lines
[
i
]
+
"
\n
"
for
i
in
top_indices
]
...
@@ -127,6 +127,7 @@ class ChatbotInterface(QWidget):
...
@@ -127,6 +127,7 @@ class ChatbotInterface(QWidget):
left_layout
=
QVBoxLayout
()
left_layout
=
QVBoxLayout
()
left_layout
.
addWidget
(
self
.
conversation_text
)
left_layout
.
addWidget
(
self
.
conversation_text
)
left_layout
.
addWidget
(
self
.
user_input_entry
)
left_layout
.
addWidget
(
self
.
user_input_entry
)
# Ajouter le bouton "Envoyer" avec une taille réduite
# Ajouter le bouton "Envoyer" avec une taille réduite
self
.
send_button
.
setMaximumWidth
(
self
.
send_button
.
width
()
//
3
)
self
.
send_button
.
setMaximumWidth
(
self
.
send_button
.
width
()
//
3
)
left_layout
.
addWidget
(
self
.
send_button
,
alignment
=
Qt
.
AlignRight
)
left_layout
.
addWidget
(
self
.
send_button
,
alignment
=
Qt
.
AlignRight
)
...
@@ -141,7 +142,7 @@ class ChatbotInterface(QWidget):
...
@@ -141,7 +142,7 @@ class ChatbotInterface(QWidget):
self
.
conversation_text
.
setSizePolicy
(
size_policy
)
self
.
conversation_text
.
setSizePolicy
(
size_policy
)
# Définir la fenêtre principale
# Définir la fenêtre principale
icon
=
QIcon
(
"
chatbot.png
"
)
# Remplacez par le chemin de votre icône
icon
=
QIcon
(
"
chatbot.png
"
)
self
.
setWindowIcon
(
icon
)
self
.
setWindowIcon
(
icon
)
self
.
setWindowTitle
(
'
chatbot
'
)
self
.
setWindowTitle
(
'
chatbot
'
)
self
.
setGeometry
(
100
,
100
,
800
,
600
)
self
.
setGeometry
(
100
,
100
,
800
,
600
)
...
@@ -167,6 +168,7 @@ class ChatbotInterface(QWidget):
...
@@ -167,6 +168,7 @@ class ChatbotInterface(QWidget):
"""
)
"""
)
self
.
user_input_entry
.
returnPressed
.
connect
(
self
.
send_message
)
self
.
user_input_entry
.
returnPressed
.
connect
(
self
.
send_message
)
self
.
history_list_widget
.
itemClicked
.
connect
(
self
.
history_item_clicked
)
self
.
history_list_widget
.
itemClicked
.
connect
(
self
.
history_item_clicked
)
...
...
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