xulh
commited on
Commit
·
f336632
1
Parent(s):
38ffda7
代码初始化
Browse files- picture/generalImg.py +4 -2
picture/generalImg.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import base64
|
| 2 |
from fastapi import APIRouter, HTTPException
|
| 3 |
from fastapi import Body
|
| 4 |
-
from huggingface_hub import InferenceClient
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
routerImg = APIRouter()
|
|
@@ -13,8 +13,10 @@ async def generate_image(token: str = Body(...), prompt: str = Body(...)):
|
|
| 13 |
# 创建InferenceClient
|
| 14 |
client = InferenceClient("black-forest-labs/FLUX.1-dev", token=token)
|
| 15 |
|
|
|
|
|
|
|
| 16 |
# 使用text_to_image方法生成图片
|
| 17 |
-
image = client.text_to_image(prompt)
|
| 18 |
|
| 19 |
# 将PIL.Image对象转换为byte数据
|
| 20 |
buffered = BytesIO()
|
|
|
|
| 1 |
import base64
|
| 2 |
from fastapi import APIRouter, HTTPException
|
| 3 |
from fastapi import Body
|
| 4 |
+
from huggingface_hub import InferenceClient, TextToImageTargetSize
|
| 5 |
from io import BytesIO
|
| 6 |
|
| 7 |
routerImg = APIRouter()
|
|
|
|
| 13 |
# 创建InferenceClient
|
| 14 |
client = InferenceClient("black-forest-labs/FLUX.1-dev", token=token)
|
| 15 |
|
| 16 |
+
targetSize = TextToImageTargetSize(height=512, width=512)
|
| 17 |
+
|
| 18 |
# 使用text_to_image方法生成图片
|
| 19 |
+
image = client.text_to_image(prompt=prompt, target_size=targetSize)
|
| 20 |
|
| 21 |
# 将PIL.Image对象转换为byte数据
|
| 22 |
buffered = BytesIO()
|