Skip to content

Commit

Permalink
feat(review_settings): 添加视频剪辑模式选择功能优化默认提示词
Browse files Browse the repository at this point in the history
- 在视频审查面板中添加剪辑模式选择选项
- 提供三种剪辑模式:仅保留音频、仅保留原声、保留原声和音频- 在 UI 中添加相应的提示信息
  • Loading branch information
linyqh committed Nov 22, 2024
1 parent 0868b8f commit 9c58102
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
12 changes: 8 additions & 4 deletions app/test/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
os.environ["HTTP_PROXY"] = config.proxy.get("http")
os.environ["HTTPS_PROXY"] = config.proxy.get("https")

genai.configure(api_key=config.app.get("vision_gemini_api_key"))
model = genai.GenerativeModel("gemini-1.5-flash")
response = model.generate_content("直接回复我文本'当前网络可用'")
print(response.text)
genai.configure(api_key="AIzaSyBnKPxuPuBpZKGKuR_Sb9CwCIJYJF-N8DM")
# genai.configure(api_key="AIzaSyCm33aPRAZ_P29gTALv0tRerMJwY3zJrq0")
model = genai.GenerativeModel("gemini-1.5-pro")


for i in range(50):
response = model.generate_content("直接回复我文本'当前网络可用'")
print(i, response.text)
18 changes: 10 additions & 8 deletions app/utils/script_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def generate_script(self, scene_description: str, word_count: int) -> str:
当前画面描述:{scene_description}
请确保新生成的文案与上文自然衔接,保持叙事的连贯性和趣味性。
不要出现除了文案以外的其他任何内容;
严格字数要求:{word_count}字,允许误差±5字。"""

messages = [
Expand Down Expand Up @@ -328,7 +329,9 @@ def __init__(self, model_name: str, api_key: str = None, base_url: str = None, p
self.generator = OpenAIGenerator(model_name, self.api_key, self.prompt, self.base_url)

def _get_default_prompt(self) -> str:
return f"""你是一位极具幽默感的短视频脚本创作大师,擅长用"温和的违反"制造笑点,让{self.video_theme}视频既有趣又富有传播力。你的任务是将视频画面描述转化为能在社交平台疯狂传播的爆款口播文案。
return f"""
你是一位极具幽默感的短视频脚本创作大师,擅长用"温和的违反"制造笑点,让主题为 《{self.video_theme}》 的视频既有趣又富有传播力。
你的任务是将视频画面描述转化为能在社交平台疯狂传播的爆款口播文案。
目标受众:热爱生活、追求独特体验的18-35岁年轻人
文案风格:基于HKRR理论 + 段子手精神
Expand All @@ -342,17 +345,16 @@ def _get_default_prompt(self) -> str:
【爆款内容四要素】
【快乐元素 Happy】
1. 用调侃的语气描述建造过程中的"笨手笨脚"
1. 用调侃的语气描述画面
2. 巧妙植入网络流行梗,增加内容的传播性
3. 适时自嘲,展现真实且有趣的一面
【知识价值 Knowledge】
1. 用段子手的方式解释专业知识(比如:"这根木头不是一般的木头,它比我前任还难搞...")
2. 把复杂的建造技巧转化为生动有趣的比喻
3. 在幽默中传递实用的野外生存技能
1. 用段子手的方式解释专业知识
2. 在幽默中传递实用的生活常识
【情感共鸣 Resonance】
1. 描述"真实但夸张"的建造困境
1. 描述"真实但夸张"的环境描述
2. 把对自然的感悟融入俏皮话中
3. 用接地气的表达方式拉近与观众距离
Expand All @@ -366,10 +368,10 @@ def _get_default_prompt(self) -> str:
2. 使用恰当的连接词和过渡语,确保叙事流畅
3. 保持人物视角和语气的一致性
4. 避免重复上一段已经提到的信息
5. 确保情节和建造过程的逻辑连续性
5. 确保情节的逻辑连续性
我会按顺序提供多段视频画面描述。请创作既搞笑又能火爆全网的口播文案。
记住:要敢于用"温和的违反"制造笑点,但要把握好尺度,让观众在轻松愉快中感受野外建造的乐趣。"""
记住:要敢于用"温和的违反"制造笑点,但要把握好尺度,让观众在轻松愉快中感受到乐趣。"""

def calculate_duration_and_word_count(self, time_range: str) -> int:
try:
Expand Down
10 changes: 0 additions & 10 deletions app/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,11 +393,7 @@ def cut_video(params, progress_callback=None):

video_script_list = st.session_state['video_clip_json']
time_list = [i['timestamp'] for i in video_script_list]

total_clips = len(time_list)

print("time_list", time_list)

def clip_progress(current, total):
progress = int((current / total) * 100)
if progress_callback:
Expand All @@ -414,17 +410,11 @@ def clip_progress(current, total):
raise ValueError("裁剪视频失败")

st.session_state['subclip_videos'] = subclip_videos

print("list:", subclip_videos)

for i, video_script in enumerate(video_script_list):
print(i)
print(video_script)
try:
video_script['path'] = subclip_videos[video_script['timestamp']]
except KeyError as err:
logger.error(f"裁剪视频失败: {err}")
# raise ValueError(f"裁剪视频失败: {err}")

return task_id, subclip_videos

Expand Down
23 changes: 13 additions & 10 deletions webui/components/review_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from loguru import logger


def render_review_panel(tr):
"""渲染视频审查面板"""
with st.expander(tr("Video Check"), expanded=False):
Expand All @@ -26,10 +27,11 @@ def render_review_panel(tr):
with cols[col]:
render_video_item(tr, video_list, subclip_videos, index)


def render_video_item(tr, video_list, subclip_videos, index):
"""渲染单个视频项"""
video_script = video_list[index]

# 显示时间戳
timestamp = video_script.get('timestamp', '')
st.text_area(
Expand All @@ -39,7 +41,7 @@ def render_video_item(tr, video_list, subclip_videos, index):
disabled=True,
key=f"timestamp_{index}"
)

# 显示视频播放器
video_path = subclip_videos.get(timestamp)
if video_path and os.path.exists(video_path):
Expand All @@ -50,7 +52,7 @@ def render_video_item(tr, video_list, subclip_videos, index):
st.error(f"无法加载视频: {os.path.basename(video_path)}")
else:
st.warning(tr("视频文件未找到"))

# 显示画面描述
st.text_area(
tr("Picture Description"),
Expand All @@ -59,7 +61,7 @@ def render_video_item(tr, video_list, subclip_videos, index):
disabled=True,
key=f"picture_{index}"
)

# 显示旁白文本
narration = st.text_area(
tr("Narration"),
Expand All @@ -71,15 +73,16 @@ def render_video_item(tr, video_list, subclip_videos, index):
if narration != video_script.get('narration', ''):
video_script['narration'] = narration
st.session_state['video_clip_json'] = video_list

# 显示剪辑模式
ost = st.selectbox(
tr("Clip Mode"),
options=range(1, 10),
index=video_script.get('OST', 1) - 1,
key=f"ost_{index}"
options=range(0, 3),
index=video_script.get('OST', 0),
key=f"ost_{index}",
help=tr("0: Keep the audio only, 1: Keep the original sound only, 2: Keep the original sound and audio")
)
# 保存修改后的剪辑模式
if ost != video_script.get('OST', 1):
if ost != video_script.get('OST', 0):
video_script['OST'] = ost
st.session_state['video_clip_json'] = video_list
st.session_state['video_clip_json'] = video_list
6 changes: 2 additions & 4 deletions webui/i18n/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,11 @@
"Video Generation Failed": "视频生成失败",
"You can download the generated video from the following links": "你可以从以下链接下载生成的视频",
"Basic Settings": "**基础设置** (:blue[点击展开])",
"Language": "界面语言",
"Pixabay API Key": "Pixabay API Key ([点击获取](https://pixabay.com/api/docs/#api_search_videos)) :red[可以不用配置,如果 Pexels 无法使用,再选择Pixabay]",
"Video LLM Provider": "视频转录大模型",
"LLM Provider": "大语言模型",
"API Key": "API Key (:red[必填,需要到大模型提供商的后台申请])",
"Base Url": "Base Url (可选)",
"Account ID": "账户ID (Cloudflare的dash面板url中获取)",
"Model Name": "模型名称 (:blue[需要到大模型提供商的后台确认被授权的模型名称])",
"Please Enter the LLM API Key": "请先填写大模型 **API Key**",
"Please Enter the Pixabay API Key": "请先填写 **Pixabay API Key**",
Expand Down Expand Up @@ -104,7 +102,6 @@
"Video Script": "视频脚本",
"Video Quality": "视频质量",
"Custom prompt for LLM, leave empty to use default prompt": "自定义提示词,留空则使用默认提示词",
"Basic Settings": "基础设置",
"Proxy Settings": "代理设置",
"Language": "界面语言",
"HTTP_PROXY": "HTTP 代理",
Expand Down Expand Up @@ -134,6 +131,7 @@
"gemini model is not available": "Gemini 模型不可用",
"NarratoAPI is available": "NarratoAPI 可用",
"NarratoAPI is not available": "NarratoAPI 不可用",
"Unsupported provider": "不支持的提供商"
"Unsupported provider": "不支持的提供商",
"0: Keep the audio only, 1: Keep the original sound only, 2: Keep the original sound and audio": "0: 仅保留音频,1: 仅保留原声,2: 保留原声和音频"
}
}

0 comments on commit 9c58102

Please sign in to comment.