Commit 6b53ae9e authored by Kavindu Randika's avatar Kavindu Randika

Merge branch 'dev-it17170062' into 'master'

chatbot implementation

See merge request !10
parents 850a4876 a79d878e
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}
......@@ -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}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment