Spaces:
Sleeping
Sleeping
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 | |
) | |
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] | |
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 |