mirror of
https://github.com/timerring/bilive.git
synced 2026-05-06 21:40:20 +08:00
feat: hidream i1 (#281)
* feat: hidream i1 * docs: update icon * docs: update docs
This commit is contained in:
@@ -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
|
||||
@@ -70,10 +71,12 @@
|
||||
- `Ideogram V_2`
|
||||
- `Recraft`
|
||||
- `Amazon Titan Image Generator V2`
|
||||
- `Hidream I1`
|
||||
|
||||
|
||||
项目架构流程如下:
|
||||
|
||||

|
||||

|
||||
|
||||
## 3. 测试硬件
|
||||
|
||||
@@ -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. 配置上传参数
|
||||
|
||||
|
||||
34
assets/hidream-color.svg
Normal file
34
assets/hidream-color.svg
Normal file
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="221px" height="32px" viewBox="0 0 221 32" enable-background="new 0 0 221 32" xml:space="preserve"> <image id="image0" width="221" height="32" x="0" y="0"
|
||||
xlink:href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAN0AAAAgCAMAAAChFo3vAAAAIGNIUk0AAHomAACAhAAA+gAAAIDo
|
||||
AAB1MAAA6mAAADqYAAAXcJy6UTwAAADwUExURQAAAACK9AOO+QON+QON+QKM+AKO+QCM8p/nCJ/l
|
||||
DJ/lC5/lC5/mC5/kCwON9wON+QON+QCO+AKN+QCZ/5/kC5/lCwOO+Z/jDAON+J/mCxgYGBkZGRsb
|
||||
GxsbGxgYGCAgIBoaGhsbGxoaGgON+Z/fEJ/mCxoaGhoaGhgYGBkZGZ7nCxoaGhoaGhoaGhsbGxkZ
|
||||
GRkZGZ/lC5/lDBkZGRDv3xDv15/fCA3s2g7u2g7u2g3u25/kC5/lCg7t2Qzr1w7u2g/v2w3s2Q7v
|
||||
2g7v2gKN+A3u2gON+ACN+g7u2Q7t2J/lCgON+Z/lCxoaGg7u2v///4hFTB4AAABLdFJOUwAwq+/+
|
||||
3IcUIK/P779wZfrhJNcFMJ9YQJxvQL+QMF8Qr49QrhCP358gcF+Az+9g34/fgG8QICBgz++vYK+A
|
||||
QN+vUJ9v17/hL99w387EyF4AAAABYktHRE9uZkFJAAAAB3RJTUUH6QQMCDMUomsZZwAABCZJREFU
|
||||
WMPVmfl/0yAUwJnz2Ok958BAGruESZN06w6n0+l0Xh39//8cgQAhKenlbD57P7TwCOR9A7z3SAAA
|
||||
K/dW7z94+Aj4ZW19Y3NrG9xVefxkKOXpM2/r9o2SrbW2zVxMVgq44fD5C0/ryxstO23buZjcGxp5
|
||||
5WldN3Q3u20bupCsWrrXntZNS7dX0UOE3viqASbqDxkJOxFpiSyKALBww7fjF3Qt3M1+pQFzjjzV
|
||||
iPNY0XJXEtoG3IG48WQ6sGHp3s1ClwgWMkbHOWuBrsd5OoVu38Btdmehy/S/oMupEpiFavqWT8c4
|
||||
70+h6x5qulrEa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f1d7WlnnmZ1ltyjPvitg37d/Vm/YTA3etWtcM3EXbdi4o+ivJD/2V5KzIoy/1
|
||||
+W67WJuH3cVv0K78rH7hOrn6dX7927au7fy5u1+4/gIzqzpRXi+XNwAAACV0RVh0ZGF0ZTpjcmVh
|
||||
dGUAMjAyNS0wNC0xMlQwODo1MToyMCswMDowMCjIYZwAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjUt
|
||||
MDQtMTJUMDg6NTE6MjArMDA6MDBZldkgAAAAKHRFWHRkYXRlOnRpbWVzdGFtcAAyMDI1LTA0LTEy
|
||||
VDA4OjUxOjIwKzAwOjAwDoD4/wAAAABJRU5ErkJggg==" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 2.7 KiB |
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -36,4 +36,4 @@ Automatically monitors and records Bilibili live broadcasts and danmaku (includi
|
||||
|
||||
The project architecture process is as follows:
|
||||
|
||||

|
||||

|
||||
@@ -91,6 +91,7 @@ IDEOGRAM_API_KEY = config.get("cover", {}).get("ideogram_api_key")
|
||||
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")
|
||||
|
||||
@@ -89,6 +89,10 @@ def cover_generator(model_type):
|
||||
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
|
||||
|
||||
79
src/cover/image_model_sdk/hidream_sdk.py
Normal file
79
src/cover/image_model_sdk/hidream_sdk.py
Normal file
@@ -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(""))
|
||||
Reference in New Issue
Block a user