Skip to content

Commit aa7f0c5

Browse files
authored
feat: recraft (#268)
* feat: recraft * docs: update docs
1 parent e9876f9 commit aa7f0c5

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212

1313
支持模型
1414

15+
<div>
1516
<img src="assets/openai.svg" alt="OpenAI whisper" width="60" height="60" />
1617
<img src="assets/zhipu-color.svg" alt="Zhipu GLM-4V-PLUS" width="60" height="60" />
1718
<img src="assets/gemini-brand-color.svg" alt="Google Gemini 1.5 Pro" width="60" height="60" />
1819
<img src="assets/qwen-color.svg" alt="Qwen-2.5-72B-Instruct" width="60" height="60" />
20+
</div>
21+
1922
<img src="assets/hunyuan-color.svg" alt="Tencent Hunyuan" width="50" height="60" />
2023
<img src="assets/minimax-color.svg" alt="Minimax" width="20" height="60" />
2124
<img src="assets/minimax-text.svg" alt="Minimax" width="60" height="60" />
@@ -26,6 +29,7 @@
2629
<img src="assets/luma-color.svg" alt="Luma Photon" width="20" height="60" />
2730
<img src="assets/luma-text.svg" alt="Luma Photon" width="60" height="60" />
2831
<img src="assets/ideogram.svg" alt="Ideogram V_2" width="50" height="60" />
32+
<img src="assets/recraft.svg" alt="Recraft" width="50" height="60" />
2933
</div>
3034

3135
## 1. Introduction
@@ -58,6 +62,7 @@
5862
- `Stable Diffusion 3.5 large turbo`
5963
- `Luma Photon`
6064
- `Ideogram V_2`
65+
- `Recraft`
6166

6267

6368
项目架构流程如下:
@@ -249,6 +254,12 @@ MLLM 模型主要用于自动切片后的切片标题生成,此功能默认关
249254
250255
请自行[注册账号](https://ideogram.ai/manage-api)并申请 API Key,填写到 `bilive.toml` 文件中对应的 `IDEOGRAM_API_KEY` 中。
251256

257+
##### 3.3.8 Recraft 模型
258+
259+
> 如需使用 Recraft 模型,请将 `IMAGE_GEN_MODEL` 参数设置为 `recraft`
260+
261+
请自行[注册账号](https://www.recraft.ai/profile/api)并申请 API Key,填写到 `bilive.toml` 文件中对应的 `RECRAFT_API_KEY` 中。
262+
252263
#### 4. bilitool 登录
253264

254265
> 由于一般日志打印不出二维码效果(docker 的日志不确定是否能打印,等发布新image时再修改,docker 版本请先参考文档 [bilive](https://bilive.timerring.com),本 README 只针对源码部署),所以这步需要提前在机器上安装 [bilitool](https://github.com/timerring/bilitool):

assets/recraft.svg

Lines changed: 1 addition & 0 deletions
Loading

bilive.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ qwen_api_key = "" # Apply for your own Qwen API key at https://bailian.console.a
3737

3838
[cover]
3939
generate_cover = false # whether to generate cover
40-
image_gen_model = "minimax" # the image generation model, can be "minimax" or "siliconflow" or "tencent" or "baidu" or "stability" or "luma" or "ideogram"
40+
image_gen_model = "minimax" # the image generation model, can be "minimax" or "siliconflow" or "tencent" or "baidu" or "stability" or "luma" or "ideogram" or "recraft"
4141
minimax_api_key = "" # Apply for your own Minimax API key at https://platform.minimaxi.com/user-center/basic-information/interface-key
4242
siliconflow_api_key = "" # Apply for your own SiliconFlow API key at https://cloud.siliconflow.cn/i/3Szr5BVg
4343
tencent_secret_id = "" # Apply for your own Tencent Cloud API key at https://console.cloud.tencent.com/cam/capi
@@ -46,3 +46,4 @@ baidu_api_key = "" # Apply for your own Baidu API key at https://console.bce.bai
4646
stability_api_key = "" # Apply for your own Stability API key at https://platform.stability.ai/account/keys
4747
luma_api_key = "" # Apply for your own Luma API key at https://lumalabs.ai/api/keys
4848
ideogram_api_key = "" # Apply for your own Ideogram API key at https://ideogram.ai/manage-api
49+
recraft_api_key = "" # Apply for your own Recraft API key at https://www.recraft.ai/profile/api

src/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,5 @@ def get_interface_config():
8181
BAIDU_API_KEY = config.get('cover', {}).get('baidu_api_key')
8282
STABILITY_API_KEY = config.get('cover', {}).get('stability_api_key')
8383
LUMA_API_KEY = config.get('cover', {}).get('luma_api_key')
84-
IDEOGRAM_API_KEY = config.get('cover', {}).get('ideogram_api_key')
84+
IDEOGRAM_API_KEY = config.get('cover', {}).get('ideogram_api_key')
85+
RECRAFT_API_KEY = config.get('cover', {}).get('recraft_api_key')

src/cover/cover_generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,10 @@ def wrapper(video_path):
8181
from .image_model_sdk.ideogram_sdk import ideogram_generate_cover
8282

8383
return ideogram_generate_cover(cover_path)
84+
elif model_type == "recraft":
85+
from .image_model_sdk.recraft_sdk import recraft_generate_cover
86+
87+
return recraft_generate_cover(cover_path)
8488
else:
8589
upload_log.error(f"Unsupported model type: {model_type}")
8690
return None
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from openai import OpenAI
2+
from src.config import RECRAFT_API_KEY
3+
import requests
4+
import os
5+
import time
6+
7+
8+
def recraft_generate_cover(your_file_path):
9+
try:
10+
client = OpenAI(
11+
base_url='https://external.api.recraft.ai/v1',
12+
api_key=RECRAFT_API_KEY,
13+
)
14+
15+
response = client.post(
16+
path='/images/imageToImage',
17+
cast_to=object,
18+
options={'headers': {'Content-Type': 'multipart/form-data'}},
19+
files={
20+
'image': open(your_file_path, 'rb'),
21+
},
22+
body={
23+
'prompt': 'This is a video screenshot, please generate a cover in the style of a manga',
24+
'strength': 0.75,
25+
},
26+
)
27+
image_url = response['data'][0]['url']
28+
img_data = requests.get(image_url).content
29+
cover_name = time.strftime("%Y%m%d%H%M%S") + ".png"
30+
temp_cover_path = os.path.join(os.path.dirname(your_file_path), cover_name)
31+
with open(temp_cover_path, "wb") as handler:
32+
handler.write(img_data)
33+
os.remove(your_file_path)
34+
return temp_cover_path
35+
except Exception as e:
36+
print(e, flush=True)
37+
return None

0 commit comments

Comments
 (0)