File size: 719 Bytes
03a8026
df32ef2
 
03a8026
df32ef2
03a8026
 
df32ef2
 
 
 
 
 
 
 
03a8026
 
df32ef2
 
 
03a8026
df32ef2
 
 
 
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

from fastai import FastApi
from fastapi.middleware.cors import CORSMiddleware
from generator import generation_function
from pydantic import BaseModel


app = FastApi()
app.add_middleware(
    CORSMiddleware,
    allow_origins=['*'],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)


class Prompt(BaseModel):
    prompts: str
    lang: str


@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