-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.py
More file actions
319 lines (288 loc) · 12.5 KB
/
Copy pathapp.py
File metadata and controls
319 lines (288 loc) · 12.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
"""Streamlit execution console for Trend2Video Pro."""
from __future__ import annotations
from pathlib import Path
from time import sleep
import streamlit as st
from src.agents.orchestrator import run_trend_to_video
from src.creator.creator_profile import load_creator_profile
PLATFORMS = ["Bilibili", "YouTube", "TikTok"]
PIPELINE_PLATFORMS = {"Bilibili": "Bilibili", "YouTube": "YouTube Shorts", "TikTok": "TikTok"}
STYLES = ["Tech", "Viral", "Educational"]
PIPELINE_STYLES = {"Tech": "Tech News", "Viral": "Viral Talking Head", "Educational": "Educational"}
DURATIONS = [30, 60, 90]
AGENT_STEPS = [
("01", "Trend Scanning", "Collect trend signal and page context"),
("02", "Opportunity Scoring", "Estimate urgency, competition, and value"),
("03", "Creator Fit", "Match topic with creator niche and audience"),
("04", "Script Writing", "Build hook, key points, value, and CTA"),
("05", "Fact Checking", "Flag risky claims before production"),
("06", "Storyboard", "Map narration to vertical scenes"),
("07", "Video Production", "Generate voiceover, subtitles, thumbnail, MP4"),
("08", "Quality Review", "Score output and export package"),
]
st.set_page_config(page_title="Trend2Video Pro", page_icon="T2V", layout="wide")
st.markdown(
"""
<style>
.block-container {padding-top: 1.6rem; max-width: 1180px;}
.hero {
padding: 34px 36px;
border-radius: 24px;
color: white;
background:
radial-gradient(circle at 85% 8%, rgba(34,211,238,.35), transparent 28%),
linear-gradient(135deg, #0f172a 0%, #164e63 56%, #0891b2 100%);
box-shadow: 0 24px 70px rgba(15,23,42,.22);
margin-bottom: 18px;
}
.hero-label {
display: inline-block;
padding: 6px 10px;
border: 1px solid rgba(255,255,255,.32);
border-radius: 999px;
font-size: 12px;
letter-spacing: .08em;
text-transform: uppercase;
opacity: .92;
margin-bottom: 14px;
}
.hero h1 {font-size: 46px; line-height: 1.05; margin: 0 0 10px 0;}
.hero p {font-size: 18px; opacity: .92; max-width: 780px; margin: 0;}
.mini-row {display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px;}
.mini-pill {
background: rgba(255,255,255,.12);
border: 1px solid rgba(255,255,255,.20);
border-radius: 999px;
padding: 8px 12px;
font-size: 13px;
}
.section-title {font-size: 22px; font-weight: 800; margin: 18px 0 8px 0;}
.section-subtitle {color: #64748b; margin-top: -4px; margin-bottom: 10px;}
div[data-testid="stMetric"] {
background: linear-gradient(135deg, #ecfeff 0%, #f8fafc 100%);
border: 1px solid #dbeafe;
padding: 14px 16px;
border-radius: 16px;
box-shadow: 0 10px 30px rgba(15,23,42,.06);
}
.agent-grid {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
margin: 4px 0 8px 0;
}
.agent-card {
border: 1px solid #e2e8f0;
border-radius: 16px;
padding: 13px 14px;
background: #ffffff;
min-height: 96px;
}
.agent-card.active {
border-color: #06b6d4;
background: linear-gradient(135deg, #ecfeff 0%, #ffffff 100%);
box-shadow: 0 14px 34px rgba(8,145,178,.16);
}
.agent-card.done {
border-color: #bae6fd;
background: #f8fafc;
}
.agent-num {font-size: 12px; color: #0891b2; font-weight: 800;}
.agent-title {font-weight: 800; margin-top: 4px;}
.agent-desc {font-size: 12px; color: #64748b; margin-top: 4px;}
.package-path {
background: #f8fafc;
border: 1px solid #e2e8f0;
border-radius: 12px;
padding: 10px 12px;
font-size: 13px;
word-break: break-all;
}
.empty-package {
border: 1px dashed #cbd5e1;
border-radius: 18px;
padding: 24px;
background: #f8fafc;
}
</style>
""",
unsafe_allow_html=True,
)
def _agent_html(active_index: int | None = None) -> str:
cards = []
for idx, (num, title, desc) in enumerate(AGENT_STEPS):
state = ""
if active_index is not None:
if idx < active_index:
state = " done"
elif idx == active_index:
state = " active"
cards.append(
f"""
<div class="agent-card{state}">
<div class="agent-num">{num}</div>
<div class="agent-title">{title}</div>
<div class="agent-desc">{desc}</div>
</div>
"""
)
return '<div class="agent-grid">' + "\n".join(cards) + "</div>"
def _read_text(path: str | Path, max_chars: int = 1200) -> str:
file_path = Path(path)
if not file_path.is_file():
return ""
return file_path.read_text(encoding="utf-8", errors="ignore")[:max_chars]
def _quality_summary(result: dict) -> list[str]:
report = result.get("report", {})
risks = report.get("risks", [])[:2]
suggestions = report.get("suggestions", [])[:2]
items = [f"Risk: {item}" for item in risks] + [f"Improve: {item}" for item in suggestions]
return items or ["No blocking publishing risk detected in the MVP quality checks."]
def _score_label(score: int) -> str:
if score >= 72:
return "High potential"
if score >= 55:
return "Worth testing"
return "Needs stronger angle"
def render_output(result: dict) -> None:
"""Render the finished creator package without raw logs or technical tables."""
files = result.get("files", {})
script = result.get("script", {})
viral = result.get("viral_prediction", {})
creator_fit = result.get("creator_fit", {})
video_score = result.get("video_score", {})
package = result.get("publish_package", {})
viral_score = round(float(viral.get("viral_probability", 0)) * 100)
st.markdown('<div class="section-title">3. Output: publish-ready package</div>', unsafe_allow_html=True)
metric_cols = st.columns(4)
metric_cols[0].metric("Viral Score", f"{viral_score}/100", _score_label(viral_score))
metric_cols[1].metric("Creator Fit", f"{round(float(creator_fit.get('creator_fit_score', 0)))}/100")
metric_cols[2].metric("Video Quality", f"{round(float(video_score.get('overall_score', video_score.get('overall_video_score', 0))))}/100")
metric_cols[3].metric("Package", "Ready" if package.get("package_dir") else "Pending")
top_left, top_right = st.columns([1.25, 1], gap="large")
with top_left:
with st.container(border=True):
st.subheader("Video preview")
video_path = Path(files.get("video", ""))
if video_path.is_file():
st.video(str(video_path))
else:
st.info("Video preview will appear here after generation.")
with top_right:
with st.container(border=True):
st.subheader("Creator assets")
title = script.get("title", result.get("input", {}).get("title", "Untitled"))
tags = " ".join("#" + str(tag).replace(" ", "") for tag in script.get("tags", []))
st.markdown(f"**Title** \n{title}")
st.markdown(f"**Hashtags** \n{tags or '#Trend #Creator #Video'}")
st.markdown(f"**Description** \n{script.get('description', 'A concise trend breakdown for creators.')}")
thumbnail_path = Path(files.get("thumbnail", ""))
if thumbnail_path.is_file():
st.image(str(thumbnail_path), caption="Thumbnail preview", use_container_width=True)
lower_left, lower_right = st.columns([1, 1], gap="large")
with lower_left:
with st.container(border=True):
st.subheader("Subtitles")
subtitles = _read_text(files.get("subtitles", ""), max_chars=900)
st.text_area("Ready-to-use SRT preview", value=subtitles, height=210, label_visibility="collapsed")
with lower_right:
with st.container(border=True):
st.subheader("Quality summary")
for item in _quality_summary(result):
st.write(f"- {item}")
if package.get("package_dir"):
st.markdown("**Publish package folder**")
st.markdown(f"<div class='package-path'>{package['package_dir']}</div>", unsafe_allow_html=True)
st.markdown("#### Download assets")
download_items = [
("MP4 Video", files.get("video")),
("Thumbnail", files.get("thumbnail")),
("Subtitles", files.get("subtitles")),
("Quality Report", files.get("report_md")),
]
cols = st.columns(4)
for col, (label, path) in zip(cols, download_items):
file_path = Path(path or "")
if file_path.is_file():
col.download_button(label, data=file_path.read_bytes(), file_name=file_path.name, use_container_width=True)
st.markdown(
"""
<div class="hero">
<div class="hero-label">Trend-to-Video Agent Framework</div>
<h1>Trend2Video Pro</h1>
<p>Input a trend, run the agent pipeline, and export a publish-ready short video package with script, subtitles, thumbnail, quality report, and MP4.</p>
<div class="mini-row">
<span class="mini-pill">No dashboard</span>
<span class="mini-pill">Mock mode ready</span>
<span class="mini-pill">Creator fit scoring</span>
<span class="mini-pill">Publish package output</span>
</div>
</div>
""",
unsafe_allow_html=True,
)
st.markdown('<div class="section-title">1. Input: trend brief</div>', unsafe_allow_html=True)
st.markdown('<div class="section-subtitle">Paste a trend title or URL. The agents decide angle, script, package, and quality status.</div>', unsafe_allow_html=True)
with st.container(border=True):
left, right = st.columns([1.35, 1], gap="large")
with left:
title = st.text_input("Trend title", value="AI Agent Trend", placeholder="Paste a product, GitHub repo, news headline, or creator trend")
url = st.text_input("Trend URL", value="", placeholder="Optional: GitHub, Product Hunt, Hacker News, news page...")
with right:
platform = st.selectbox("Platform", PLATFORMS, index=0)
style = st.selectbox("Style", STYLES, index=0)
duration = st.selectbox("Duration", DURATIONS, index=1, format_func=lambda value: f"{value} seconds")
generate = st.button("Generate Video Package", type="primary", use_container_width=True)
st.markdown('<div class="section-title">2. Execute: agent pipeline</div>', unsafe_allow_html=True)
progress_box = st.container(border=True)
if generate:
with progress_box:
progress = st.progress(0)
status = st.empty()
agent_area = st.empty()
for index, (_, step, _) in enumerate(AGENT_STEPS):
status.markdown(f"**Running:** {step}")
agent_area.markdown(_agent_html(index), unsafe_allow_html=True)
progress.progress((index + 1) / len(AGENT_STEPS))
sleep(0.16)
status.markdown("**Finalizing:** Exporting publish-ready package")
with st.spinner("Building your creator-ready package..."):
result = run_trend_to_video(
{"title": title, "url": url, "description": ""},
creator_profile=load_creator_profile(),
platform=PIPELINE_PLATFORMS[platform],
style=PIPELINE_STYLES[style],
duration=int(duration),
)
st.session_state["last_result"] = result
with progress_box:
st.success("Package ready. Review the final assets below.")
else:
with progress_box:
st.markdown(_agent_html(), unsafe_allow_html=True)
if "last_result" in st.session_state:
render_output(st.session_state["last_result"])
else:
st.markdown('<div class="section-title">3. Output: publish-ready package</div>', unsafe_allow_html=True)
with st.container(border=True):
preview, assets = st.columns([1.15, 1], gap="large")
with preview:
st.markdown(
"""
<div class="empty-package">
<h3>Video preview will appear here</h3>
<p>Run the pipeline to generate a vertical MP4, thumbnail, subtitles, description, hashtags, and quality report.</p>
</div>
""",
unsafe_allow_html=True,
)
with assets:
st.subheader("Package checklist")
st.write("- video.mp4")
st.write("- thumbnail.png")
st.write("- title.txt")
st.write("- description.txt")
st.write("- hashtags.txt")
st.write("- subtitles.srt")
st.write("- quality_report.md")
st.write("- metadata.json")