Spaces:
Runtime error
Runtime error
File size: 1,253 Bytes
1a60352 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
from load_meta_data import ChatBot
from enum import Enum
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
class Repo_ID(Enum):
chat_model: str = "Mohammed-Altaf/medical_chatbot-8bit"
app = FastAPI()
bot = ChatBot()
# middlewares
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=['*'],
allow_headers=['*'],
)
# load the model asynchronously on startup
@app.on_event("startup")
async def startup():
bot.load_from_hub(Repo_ID.chat_model.value)
@app.get("/")
async def home():
"Home route for the api"
return {"messeage":"welcome, Application Successfully Loaded!!"}
# dummy test route
@app.get("/test_response/{query}")
async def test_inference(query:str):
return query
@app.get("/query/{user_query}")
async def inference_output(user_query: str) -> str:
"""Main query route for the api, which return the response from the inference of the LanguageModel
Keyword arguments:
user_query -- Input string from the user, which is the question(input) to the Model
Return: return's the response got from the Language model
"""
global bot
response = bot.get_response(user_query)
return response
|