File size: 912 Bytes
239290b |
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 |
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} |