Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Skin disease Server
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Skin disease
Skin disease Server
Commits
6b53ae9e
Commit
6b53ae9e
authored
Oct 11, 2021
by
Kavindu Randika
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'dev-it17170062' into 'master'
chatbot implementation See merge request
!10
parents
850a4876
a79d878e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
8 deletions
+48
-8
routes/chatbot.py
routes/chatbot.py
+38
-0
routes/doctor.py
routes/doctor.py
+10
-8
No files found.
routes/chatbot.py
0 → 100644
View file @
6b53ae9e
from
fastapi
import
APIRouter
from
transformers
import
AutoTokenizer
,
AutoModelWithLMHead
,
AutoConfig
import
torch
from
os
import
error
from
pydantic
import
BaseModel
disease
=
APIRouter
()
class
Message
(
BaseModel
):
msg
:
str
@
disease
.
post
(
'/api/chatbot'
)
async
def
create_disease
(
message
:
Message
):
try
:
tokenizerx
=
AutoTokenizer
.
from_pretrained
(
pretrained_model_name_or_path
=
"t5-base"
)
model
=
AutoModelWithLMHead
.
from_pretrained
(
"./chatbot/t5-bot/best_tfmr"
)
text
=
message
device
=
torch
.
device
(
"cuda:0"
if
torch
.
cuda
.
is_available
()
else
"cpu"
)
preprocess_text
=
text
.
strip
()
.
replace
(
"
\n
"
,
""
)
tokenized_text
=
tokenizerx
.
encode
(
preprocess_text
,
return_tensors
=
"pt"
)
.
to
(
device
)
model
=
model
.
to
(
device
)
outs
=
model
.
generate
(
tokenized_text
,
temperature
=
1.5
,
length_penalty
=
1.5
,
max_length
=
128
,
num_beams
=
1
,
early_stopping
=
True
,
no_repeat_ngram_size
=
2
)
dec
=
[
tokenizerx
.
decode
(
ids
)
for
ids
in
outs
]
print
(
"Predicted Answer: "
,
dec
)
return
{
"success"
:
True
,
"msg"
:
dec
}
except
error
:
return
{
"success"
:
False
,
"msg"
:
error
}
routes/doctor.py
View file @
6b53ae9e
...
...
@@ -10,9 +10,15 @@ from schemas.availability import availabilityEntity, availabilitiesEntity
from
fastapi
import
APIRouter
from
models.doctor
import
Doctor
from
config.db
import
conn
from
pydantic
import
BaseModel
doctor
=
APIRouter
()
class
Availabilities
(
BaseModel
):
availabilities
:
List
[
Availability
]
@
doctor
.
get
(
'/api/doctors'
)
async
def
find_all_doctors
():
return
doctorsEntity
(
conn
.
skinDiseaseDB
.
doctor
.
find
())
...
...
@@ -52,14 +58,10 @@ async def delete_doctor(id):
@
doctor
.
put
(
'/api/availability/{id}'
)
async
def
update_availability
(
id
,
availabilities
:
List
[
Availability
]):
try
:
available_dic
=
dict
()
for
available
in
availabilities
:
print
(
available
)
#conn.skinDiseaseDB.doctor.find_one_and_update({"id":id},{"$set": {'isAvailable': isAvailable}})
return
availabilities
async
def
update_availability
(
id
,
availabilities
:
Availabilities
):
try
:
conn
.
skinDiseaseDB
.
doctor
.
find_one_and_update
({
"serviceID"
:
id
},
{
"$set"
:
{
'availability'
:
availabilities
}})
return
{
"success"
:
True
,
}
except
error
:
return
{
"success"
:
False
,
"msg"
:
error
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment