Spaces:
Sleeping
Sleeping
AndriiPets
commited on
Commit
•
df32ef2
1
Parent(s):
579fc35
switch to fasapi
Browse files
main.py
CHANGED
@@ -1,22 +1,28 @@
|
|
1 |
|
2 |
-
from
|
|
|
3 |
from generator import generation_function
|
4 |
-
from
|
5 |
-
from flask_cors import CORS
|
6 |
-
import asyncio
|
7 |
|
8 |
-
app = Flask(__name__)
|
9 |
-
CORS(app)
|
10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
@app.route('/')
|
13 |
-
def hello():
|
14 |
-
return 'Hello world!'
|
15 |
|
|
|
|
|
|
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
20 |
|
21 |
text = request_data["prompts"]
|
22 |
|
@@ -27,7 +33,3 @@ def generate():
|
|
27 |
generated_recepie = generation_function(text)
|
28 |
|
29 |
return generated_recepie
|
30 |
-
|
31 |
-
|
32 |
-
if __name__ == '__main__':
|
33 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
1 |
|
2 |
+
from fastai import FastApi
|
3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
4 |
from generator import generation_function
|
5 |
+
from pydantic import BaseModel
|
|
|
|
|
6 |
|
|
|
|
|
7 |
|
8 |
+
app = FastApi()
|
9 |
+
app.add_middleware(
|
10 |
+
CORSMiddleware,
|
11 |
+
allow_origins=['*'],
|
12 |
+
allow_credentials=True,
|
13 |
+
allow_methods=["*"],
|
14 |
+
allow_headers=["*"],
|
15 |
+
)
|
16 |
|
|
|
|
|
|
|
17 |
|
18 |
+
class Prompt(BaseModel):
|
19 |
+
prompts: str
|
20 |
+
lang: str
|
21 |
|
22 |
+
|
23 |
+
@app.post('/generate')
|
24 |
+
def generate(prompt: Prompt):
|
25 |
+
request_data = prompt.dict()
|
26 |
|
27 |
text = request_data["prompts"]
|
28 |
|
|
|
33 |
generated_recepie = generation_function(text)
|
34 |
|
35 |
return generated_recepie
|
|
|
|
|
|
|
|