Skip to content

Commit 710029d

Browse files
authored
feat: hidream i1 (#281)
* feat: hidream i1 * docs: update icon * docs: update docs
1 parent 73fabc1 commit 710029d

File tree

7 files changed

+128
-5
lines changed

7 files changed

+128
-5
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<img src="assets/ideogram.svg" alt="Ideogram V_2" width="50" height="60" />
3333
<img src="assets/recraft.svg" alt="Recraft" width="50" height="60" />
3434
<img src="assets/aws-color.svg" alt="Amazon" width="50" height="60" />
35+
<img src="assets/hidream-color.svg" alt="Hidream I1" width="100" height="60" />
3536
</div>
3637

3738
## 1. Introduction
@@ -70,10 +71,12 @@
7071
- `Ideogram V_2`
7172
- `Recraft`
7273
- `Amazon Titan Image Generator V2`
74+
- `Hidream I1`
75+
7376

7477
项目架构流程如下:
7578

76-
![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2025-04-12-14-46-16.png)
79+
![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2025-04-12-17-04-11.png)
7780

7881
## 3. 测试硬件
7982

@@ -207,6 +210,7 @@ MLLM 模型主要用于自动切片后的切片标题生成,此功能默认关
207210
| Ideogram | Ideogram V_2 | `ideogram` | [ideogram_api_key](https://ideogram.ai/manage-api) |
208211
| Recraft | Recraft V3 | `recraft` | [recraft_api_key](https://www.recraft.ai/profile/api) |
209212
| Amazon | Titan Image Generator V2 | `amazon` | [aws_access_key_id and aws_secret_access_key](https://aws.amazon.com/console/) |
213+
| Hidream | Hidream I1 | `hidream` | [hidream_api_key](https://www.hidreamai.com/platform/token) |
210214

211215
#### 3. 配置上传参数
212216

assets/hidream-color.svg

Lines changed: 34 additions & 0 deletions
Loading

bilive.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ slice_num = 2 # the number of slices
3030
slice_overlap = 30 # the overlap of slices(seconds) see my package https://github.com/timerring/auto-slice-video for more details
3131
slice_step = 1 # the step of slices(seconds)
3232
min_video_size = 200 # The minimum video size to be sliced (MB)
33-
mllm_model = "qwen" # the multi-model LLMs, can be "qwen" or "gemini" or "zhipu"
33+
mllm_model = "qwen" # the multi-model LLMs, can be "qwen" or "gemini" or "zhipu" or "sensenova"
3434
qwen_api_key = "" # Apply for your own Qwen API key at https://bailian.console.aliyun.com/?apiKey=1
3535
zhipu_api_key = "" # Apply for your own GLM-4v-Plus API key at https://www.bigmodel.cn/invite?icode=shBtZUfNE6FfdMH1R6NybGczbXFgPRGIalpycrEwJ28%3D
3636
gemini_api_key = "" # Apply for your own Gemini API key at https://aistudio.google.com/app/apikey
@@ -39,7 +39,7 @@ sensenova_api_key = "" # Apply for your own SenseNova API key at https://console
3939
[cover]
4040
generate_cover = false # whether to generate cover
4141
cover_prompt = "" # Write your own cover prompt here
42-
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" or "amazon"
42+
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" or "amazon" or "hidream"
4343
minimax_api_key = "" # Apply for your own Minimax API key at https://platform.minimaxi.com/user-center/basic-information/interface-key
4444
siliconflow_api_key = "" # Apply for your own SiliconFlow API key at https://cloud.siliconflow.cn/i/3Szr5BVg
4545
tencent_secret_id = "" # Apply for your own Tencent Cloud API key at https://console.cloud.tencent.com/cam/capi
@@ -50,4 +50,5 @@ luma_api_key = "" # Apply for your own Luma API key at https://lumalabs.ai/api/k
5050
ideogram_api_key = "" # Apply for your own Ideogram API key at https://ideogram.ai/manage-api
5151
recraft_api_key = "" # Apply for your own Recraft API key at https://www.recraft.ai/profile/api
5252
aws_access_key_id = "" # Apply for your own AWS access key id at https://aws.amazon.com/console/
53-
aws_secret_access_key = "" # Apply for your own AWS secret access key as above
53+
aws_secret_access_key = "" # Apply for your own AWS secret access key as above
54+
hidream_api_key = "" # Apply for your own Hidream API key at https://www.hidreamai.com/platform/token

docs/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ Automatically monitors and records Bilibili live broadcasts and danmaku (includi
3636

3737
The project architecture process is as follows:
3838

39-
![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2025-04-12-14-46-16.png)
39+
![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2025-04-12-17-04-11.png)

src/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def get_interface_config():
9191
RECRAFT_API_KEY = config.get("cover", {}).get("recraft_api_key")
9292
AWS_ACCESS_KEY_ID = config.get("cover", {}).get("aws_access_key_id")
9393
AWS_SECRET_ACCESS_KEY = config.get("cover", {}).get("aws_secret_access_key")
94+
HIDREAM_API_KEY = config.get("cover", {}).get("hidream_api_key")
9495

9596
SLICE_PROMPT = config.get("slice", {}).get("slice_prompt")
9697
COVER_PROMPT = config.get("cover", {}).get("cover_prompt")

src/cover/cover_generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def wrapper(video_path):
8989
from .image_model_sdk.amazon_sdk import amazon_generate_cover
9090

9191
return amazon_generate_cover(cover_path)
92+
elif model_type == "hidream":
93+
from .image_model_sdk.hidream_sdk import hidream_generate_cover
94+
95+
return hidream_generate_cover(cover_path)
9296
else:
9397
upload_log.error(f"Unsupported model type: {model_type}")
9498
return None
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import requests
2+
import json
3+
import uuid
4+
import base64
5+
from src.config import HIDREAM_API_KEY, COVER_PROMPT
6+
7+
def get_image_base64(image_path):
8+
with open(image_path, "rb") as image_file:
9+
return base64.b64encode(image_file.read()).decode("utf-8")
10+
11+
def _get_task_id(image_path):
12+
image_base64 = get_image_base64(image_path)
13+
headers = {
14+
'Authorization': f'Bearer {HIDREAM_API_KEY}',
15+
'Content-Type': 'application/json',
16+
'API-User-ID': ''
17+
}
18+
19+
data = {
20+
"image": image_base64,
21+
"prompt": COVER_PROMPT,
22+
"negative_prompt": "sun",
23+
"img_count": 1,
24+
"version": "v1",
25+
"resolution": "2048*2048",
26+
"request_id": str(uuid.uuid4())
27+
}
28+
29+
url = 'https://www.hidreamai.com/api-pub/gw/v3/image/img2img/async'
30+
response = requests.post(url, headers=headers, data=json.dumps(data))
31+
32+
if response.status_code == 200:
33+
if response.json()['code'] == 0:
34+
task_id = response.json()['result']['task_id']
35+
return task_id
36+
else:
37+
print(response.json()['message'])
38+
return None
39+
else:
40+
print(response.status_code)
41+
return None
42+
43+
def hidream_generate_cover(your_file_path):
44+
task_id = _get_task_id(your_file_path)
45+
if task_id:
46+
headers = {
47+
'Authorization': f'Bearer {HIDREAM_API_KEY}'
48+
}
49+
50+
params = {
51+
'task_id': task_id,
52+
'request_id': ''
53+
}
54+
55+
url = 'https://www.hidreamai.com/api-pub/gw/v3/image/img2img/async/results'
56+
response = requests.get(url, headers=headers, params=params)
57+
58+
if response.status_code == 200:
59+
if response.json()['code'] == 0:
60+
image_url = response.json()['result']['sub_task_results']['image']
61+
img_data = requests.get(image_url).content
62+
cover_name = time.strftime("%Y%m%d%H%M%S") + ".jpg"
63+
temp_cover_path = os.path.join(os.path.dirname(your_file_path), cover_name)
64+
with open(temp_cover_path, "wb") as handler:
65+
handler.write(img_data)
66+
os.remove(your_file_path)
67+
return temp_cover_path
68+
else:
69+
print(response.json()['message'])
70+
return None
71+
else:
72+
print(response.status_code)
73+
return None
74+
else:
75+
return None
76+
77+
78+
if __name__ == "__main__":
79+
print(hidream_generate_cover(""))

0 commit comments

Comments
 (0)