Spaces:
Sleeping
Sleeping
File size: 823 Bytes
03a8026 c9d1ed3 df32ef2 03a8026 df32ef2 03a8026 b2ea0e8 df32ef2 03a8026 df32ef2 03a8026 df32ef2 8142ceb 03a8026 8142ceb 03a8026 8142ceb 03a8026 8142ceb 03a8026 |
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 42 |
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from generator import generation_function
from pydantic import BaseModel
app = FastAPI(docs_url="/")
app.add_middleware(
CORSMiddleware,
allow_origins=['*'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class Prompt(BaseModel):
prompts: str
lang: str
@app.get("/test")
def test(input: str):
output = input
return {"input": output}
@app.post("/generate/")
def generate(prompt: Prompt):
request_data = prompt.dict()
text = request_data["prompts"]
if request_data.get("lang"):
generated_recepie = generation_function(
text, lang=request_data["lang"])
else:
generated_recepie = generation_function(text)
return generated_recepie
|