vis / app.py
Guhanselvam's picture
Create app.py
695f082 verified
raw
history blame contribute delete
593 Bytes
# app.py
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from chatbot_model import ChatbotModel
# Initialize FastAPI
app = FastAPI()
# Load your model (e.g., "gpt2")
chatbot_model = ChatbotModel("gpt2") # Modify this based on the model you want to use
class ChatRequest(BaseModel):
message: str
@app.post("/chat/")
async def chat(request: ChatRequest):
try:
bot_response = chatbot_model.get_response(request.message)
return {"response": bot_response}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))