Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,29 +1,28 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
| 3 |
-
from transformers import pipeline
|
| 4 |
-
import os
|
| 5 |
import asyncio
|
| 6 |
from contextlib import asynccontextmanager
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
app
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
try:
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
"sentiment": result['label'],
|
| 26 |
-
"confidence": round(result['score'], 4)
|
| 27 |
-
}
|
| 28 |
except Exception as e:
|
| 29 |
return {"error": str(e)}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from pydantic import BaseModel
|
|
|
|
|
|
|
| 3 |
import asyncio
|
| 4 |
from contextlib import asynccontextmanager
|
| 5 |
|
| 6 |
+
class ImageRequest(BaseModel): # Новая модель для запроса
|
| 7 |
+
prompt: str
|
| 8 |
+
model: str = "flux_1_schnell"
|
| 9 |
+
size: str = "1_1_HD"
|
| 10 |
+
is_public: bool = False
|
| 11 |
|
| 12 |
+
@app.post("/generate-image")
|
| 13 |
+
async def generate_image(request: ImageRequest):
|
| 14 |
+
url = "https://api.fastflux.co/v1/images/generate"
|
| 15 |
+
headers = {"Content-Type": "application/json"}
|
| 16 |
+
json_data = {
|
| 17 |
+
"prompt": request.prompt,
|
| 18 |
+
"model": request.model,
|
| 19 |
+
"size": request.size,
|
| 20 |
+
"isPublic": request.is_public
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
try:
|
| 24 |
+
response = requests.post(url, headers=headers, json=json_data)
|
| 25 |
+
response.raise_for_status()
|
| 26 |
+
return response.json()
|
|
|
|
|
|
|
|
|
|
| 27 |
except Exception as e:
|
| 28 |
return {"error": str(e)}
|