from fastapi import FastAPI, Request from fastapi.middleware.cors import CORSMiddleware from QuoteGenerator import QuoteGenerator from typing import Union from pydantic import BaseModel class QuoteRequest(BaseModel): tags: Union[None, str] app = FastAPI() origins = ['https://quote-generator.streamlit.app/'] # Setting up cors app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["GET", "POST"], allow_headers=["*"] ) quote_generator = QuoteGenerator() quote_generator.load_generator() @app.get("/") def root(request: Request): print("URL ", request.url.path) return {"message": "This is the website for quote-generator"} @app.post("/generate_quote") def generate_quote(req: QuoteRequest): print("Tags: ", req.tags) generated_quote_oup = quote_generator.generate_quote(req.tags) return {'quote': generated_quote_oup}