Mohammed-Altaf commited on
Commit
1a60352
1 Parent(s): 84ca46a

added main file

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