Spaces:
Sleeping
Sleeping
File size: 897 Bytes
af16851 b64d09e af16851 b64d09e af16851 b64d09e af16851 b64d09e af16851 b64d09e af16851 b64d09e af16851 |
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 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import chatbot
app = FastAPI()
model = None
# Add CORS middleware to allow any origin
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows all origins
allow_credentials=True,
allow_methods=["*"], # Allows all methods (GET, POST, etc.)
allow_headers=["*"], # Allows all headers
)
@app.get("/")
def root():
return "Hello World"
# Define the Pydantic model to parse JSON input
from pydantic import BaseModel
class HistoryRequest(BaseModel):
user: list[str]
ai: list[str]
@app.post("/generate")
def generate_response(history: HistoryRequest):
try:
model
except:
model = chatbot.ChatBot()
if type(model) != type(chatbot.ChatBot()):
model = chatbot.ChatBot()
response = model.generate_response(history)
return response |