Voffchik commited on
Commit
6be6a10
·
verified ·
1 Parent(s): d3b0f55

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -4,16 +4,23 @@ import requests # Добавляем импорт
4
  import asyncio
5
  from contextlib import asynccontextmanager
6
 
 
 
 
 
 
 
 
 
 
 
7
  class ImageRequest(BaseModel): # Новая модель для запроса
8
  prompt: str
9
  model: str = "flux_1_schnell"
10
  size: str = "1_1_HD"
11
  is_public: bool = False
12
 
13
- app = FastAPI(lifespan=lifespan)
14
-
15
  @app.post("/generate-image")
16
-
17
  async def generate_image(request: ImageRequest):
18
  url = "https://api.fastflux.co/v1/images/generate"
19
  headers = {"Content-Type": "application/json"}
 
4
  import asyncio
5
  from contextlib import asynccontextmanager
6
 
7
+ @asynccontextmanager
8
+ async def lifespan(app: FastAPI):
9
+ # Здесь можно инициализировать ресурсы
10
+ yield
11
+ # Здесь можно освободить ресурсы
12
+
13
+ app = FastAPI(lifespan=lifespan)
14
+
15
+
16
+
17
  class ImageRequest(BaseModel): # Новая модель для запроса
18
  prompt: str
19
  model: str = "flux_1_schnell"
20
  size: str = "1_1_HD"
21
  is_public: bool = False
22
 
 
 
23
  @app.post("/generate-image")
 
24
  async def generate_image(request: ImageRequest):
25
  url = "https://api.fastflux.co/v1/images/generate"
26
  headers = {"Content-Type": "application/json"}