Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<img src="assets/ideogram.svg" alt="Ideogram V_2" width="50" height="60" />
<img src="assets/recraft.svg" alt="Recraft" width="50" height="60" />
<img src="assets/aws-color.svg" alt="Amazon" width="50" height="60" />
<img src="assets/hidream-color.svg" alt="Hidream I1" width="100" height="60" />
</div>

## 1. Introduction
Expand Down Expand Up @@ -70,10 +71,12 @@
- `Ideogram V_2`
- `Recraft`
- `Amazon Titan Image Generator V2`
- `Hidream I1`


项目架构流程如下:

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

## 3. 测试硬件

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

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

Expand Down
34 changes: 34 additions & 0 deletions assets/hidream-color.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions bilive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ slice_num = 2 # the number of slices
slice_overlap = 30 # the overlap of slices(seconds) see my package https://github.com/timerring/auto-slice-video for more details
slice_step = 1 # the step of slices(seconds)
min_video_size = 200 # The minimum video size to be sliced (MB)
mllm_model = "qwen" # the multi-model LLMs, can be "qwen" or "gemini" or "zhipu"
mllm_model = "qwen" # the multi-model LLMs, can be "qwen" or "gemini" or "zhipu" or "sensenova"
qwen_api_key = "" # Apply for your own Qwen API key at https://bailian.console.aliyun.com/?apiKey=1
zhipu_api_key = "" # Apply for your own GLM-4v-Plus API key at https://www.bigmodel.cn/invite?icode=shBtZUfNE6FfdMH1R6NybGczbXFgPRGIalpycrEwJ28%3D
gemini_api_key = "" # Apply for your own Gemini API key at https://aistudio.google.com/app/apikey
Expand All @@ -39,7 +39,7 @@ sensenova_api_key = "" # Apply for your own SenseNova API key at https://console
[cover]
generate_cover = false # whether to generate cover
cover_prompt = "" # Write your own cover prompt here
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"
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"
minimax_api_key = "" # Apply for your own Minimax API key at https://platform.minimaxi.com/user-center/basic-information/interface-key
siliconflow_api_key = "" # Apply for your own SiliconFlow API key at https://cloud.siliconflow.cn/i/3Szr5BVg
tencent_secret_id = "" # Apply for your own Tencent Cloud API key at https://console.cloud.tencent.com/cam/capi
Expand All @@ -50,4 +50,5 @@ luma_api_key = "" # Apply for your own Luma API key at https://lumalabs.ai/api/k
ideogram_api_key = "" # Apply for your own Ideogram API key at https://ideogram.ai/manage-api
recraft_api_key = "" # Apply for your own Recraft API key at https://www.recraft.ai/profile/api
aws_access_key_id = "" # Apply for your own AWS access key id at https://aws.amazon.com/console/
aws_secret_access_key = "" # Apply for your own AWS secret access key as above
aws_secret_access_key = "" # Apply for your own AWS secret access key as above
hidream_api_key = "" # Apply for your own Hidream API key at https://www.hidreamai.com/platform/token
2 changes: 1 addition & 1 deletion docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ Automatically monitors and records Bilibili live broadcasts and danmaku (includi

The project architecture process is as follows:

![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2025-04-12-14-46-16.png)
![](https://cdn.jsdelivr.net/gh/timerring/scratchpad2023/2024/2025-04-12-17-04-11.png)
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def get_interface_config():
RECRAFT_API_KEY = config.get("cover", {}).get("recraft_api_key")
AWS_ACCESS_KEY_ID = config.get("cover", {}).get("aws_access_key_id")
AWS_SECRET_ACCESS_KEY = config.get("cover", {}).get("aws_secret_access_key")
HIDREAM_API_KEY = config.get("cover", {}).get("hidream_api_key")

SLICE_PROMPT = config.get("slice", {}).get("slice_prompt")
COVER_PROMPT = config.get("cover", {}).get("cover_prompt")
4 changes: 4 additions & 0 deletions src/cover/cover_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ def wrapper(video_path):
from .image_model_sdk.amazon_sdk import amazon_generate_cover

return amazon_generate_cover(cover_path)
elif model_type == "hidream":
from .image_model_sdk.hidream_sdk import hidream_generate_cover

return hidream_generate_cover(cover_path)
else:
upload_log.error(f"Unsupported model type: {model_type}")
return None
Expand Down
79 changes: 79 additions & 0 deletions src/cover/image_model_sdk/hidream_sdk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import requests
import json
import uuid
import base64
from src.config import HIDREAM_API_KEY, COVER_PROMPT

def get_image_base64(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")

def _get_task_id(image_path):
image_base64 = get_image_base64(image_path)
headers = {
'Authorization': f'Bearer {HIDREAM_API_KEY}',
'Content-Type': 'application/json',
'API-User-ID': ''
}

data = {
"image": image_base64,
"prompt": COVER_PROMPT,
"negative_prompt": "sun",
"img_count": 1,
"version": "v1",
"resolution": "2048*2048",
"request_id": str(uuid.uuid4())
}

url = 'https://www.hidreamai.com/api-pub/gw/v3/image/img2img/async'
response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
if response.json()['code'] == 0:
task_id = response.json()['result']['task_id']
return task_id
else:
print(response.json()['message'])
return None
else:
print(response.status_code)
return None

def hidream_generate_cover(your_file_path):
task_id = _get_task_id(your_file_path)
if task_id:
headers = {
'Authorization': f'Bearer {HIDREAM_API_KEY}'
}

params = {
'task_id': task_id,
'request_id': ''
}

url = 'https://www.hidreamai.com/api-pub/gw/v3/image/img2img/async/results'
response = requests.get(url, headers=headers, params=params)

if response.status_code == 200:
if response.json()['code'] == 0:
image_url = response.json()['result']['sub_task_results']['image']
img_data = requests.get(image_url).content
cover_name = time.strftime("%Y%m%d%H%M%S") + ".jpg"
temp_cover_path = os.path.join(os.path.dirname(your_file_path), cover_name)
with open(temp_cover_path, "wb") as handler:
handler.write(img_data)
os.remove(your_file_path)
return temp_cover_path
else:
print(response.json()['message'])
return None
else:
print(response.status_code)
return None
else:
return None


if __name__ == "__main__":
print(hidream_generate_cover(""))