Guhanselvam commited on
Commit
695f082
·
verified ·
1 Parent(s): 5367a48

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ from fastapi import FastAPI, HTTPException
3
+ from pydantic import BaseModel
4
+ from chatbot_model import ChatbotModel
5
+
6
+ # Initialize FastAPI
7
+ app = FastAPI()
8
+
9
+ # Load your model (e.g., "gpt2")
10
+ chatbot_model = ChatbotModel("gpt2") # Modify this based on the model you want to use
11
+
12
+ class ChatRequest(BaseModel):
13
+ message: str
14
+
15
+ @app.post("/chat/")
16
+ async def chat(request: ChatRequest):
17
+ try:
18
+ bot_response = chatbot_model.get_response(request.message)
19
+ return {"response": bot_response}
20
+ except Exception as e:
21
+ raise HTTPException(status_code=500, detail=str(e))