Skip to content

Commit e9876f9

Browse files
authored
feat: ideogram v2 (#267)
* feat: ideogram v2 * docs: update icon
1 parent eee1547 commit e9876f9

File tree

6 files changed

+70
-2
lines changed

6 files changed

+70
-2
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
<img src="assets/stability-brand-color.svg" alt="Stability AI" width="80" height="60" />
2626
<img src="assets/luma-color.svg" alt="Luma Photon" width="20" height="60" />
2727
<img src="assets/luma-text.svg" alt="Luma Photon" width="60" height="60" />
28+
<img src="assets/ideogram.svg" alt="Ideogram V_2" width="50" height="60" />
2829
</div>
2930

3031
## 1. Introduction
@@ -56,6 +57,9 @@
5657
- `Baidu ERNIE irag-1.0`
5758
- `Stable Diffusion 3.5 large turbo`
5859
- `Luma Photon`
60+
- `Ideogram V_2`
61+
62+
5963
项目架构流程如下:
6064

6165
```mermaid
@@ -239,6 +243,12 @@ MLLM 模型主要用于自动切片后的切片标题生成,此功能默认关
239243
240244
请自行[注册账号](https://lumalabs.ai/api/keys)并申请 API Key,填写到 `bilive.toml` 文件中对应的 `LUMA_API_KEY` 中。
241245

246+
##### 3.3.7 Ideogram V_2 模型
247+
248+
> 如需使用 Ideogram V_2 模型,请将 `IMAGE_GEN_MODEL` 参数设置为 `ideogram`
249+
250+
请自行[注册账号](https://ideogram.ai/manage-api)并申请 API Key,填写到 `bilive.toml` 文件中对应的 `IDEOGRAM_API_KEY` 中。
251+
242252
#### 4. bilitool 登录
243253

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

assets/ideogram.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,11 +37,12 @@ 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"
40+
image_gen_model = "minimax" # the image generation model, can be "minimax" or "siliconflow" or "tencent" or "baidu" or "stability" or "luma" or "ideogram"
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
4444
tencent_secret_key = "" # Apply for your own Tencent Cloud secret key as above
4545
baidu_api_key = "" # Apply for your own Baidu API key at https://console.bce.baidu.com/iam/key/list
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
48+
ideogram_api_key = "" # Apply for your own Ideogram API key at https://ideogram.ai/manage-api

src/config.py

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

src/cover/cover_generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def wrapper(video_path):
7777
from .image_model_sdk.luma_sdk import luma_generate_cover
7878

7979
return luma_generate_cover(cover_path)
80+
elif model_type == "ideogram":
81+
from .image_model_sdk.ideogram_sdk import ideogram_generate_cover
82+
83+
return ideogram_generate_cover(cover_path)
8084
else:
8185
upload_log.error(f"Unsupported model type: {model_type}")
8286
return None
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import requests
2+
import json
3+
import os
4+
import time
5+
from src.config import IDEOGRAM_API_KEY
6+
7+
8+
def ideogram_generate_cover(your_file_path):
9+
"""Generater cover image using ideogram V_2 model
10+
Args:
11+
your_file_path: str, path to the image file
12+
Returns:
13+
str, local download path of the generated cover image file
14+
"""
15+
try:
16+
url = "https://api.ideogram.ai/remix"
17+
18+
files = {"image_file": open(your_file_path, "rb")}
19+
payload = {
20+
"image_request": json.dumps(
21+
{
22+
"prompt": "This is a video screenshot, please generate a cover in the style of a manga",
23+
"aspect_ratio": "ASPECT_10_16",
24+
"image_weight": 75,
25+
"magic_prompt_option": "ON",
26+
"model": "V_2",
27+
}
28+
)
29+
}
30+
headers = {"Api-Key": f"{IDEOGRAM_API_KEY}"}
31+
32+
response = requests.post(url, data=payload, files=files, headers=headers)
33+
if response.status_code == 200:
34+
response_json = response.json()
35+
image_url = response_json["data"][0]["url"]
36+
img_data = requests.get(image_url).content
37+
cover_name = time.strftime("%Y%m%d%H%M%S") + ".png"
38+
temp_cover_path = os.path.join(os.path.dirname(your_file_path), cover_name)
39+
with open(temp_cover_path, "wb") as handler:
40+
handler.write(img_data)
41+
os.remove(your_file_path)
42+
return temp_cover_path
43+
else:
44+
raise Exception(response.text)
45+
except Exception as e:
46+
print(e, flush=True)
47+
return None
48+
49+
50+
if __name__ == "__main__":
51+
print(ideogram_generate_cover(""))

0 commit comments

Comments
 (0)