Spaces:
Sleeping
Sleeping
File size: 5,496 Bytes
a3c17c2 | 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 | """4๊ฐ ์์ ์์ ์ผ๊ด ๋ถ์ โ Streamlit ์์ด ๋น ๋ฅด๊ฒ ๊ฒ์ฆ.
์ฌ์ฉ:
python cli_test.py # `๋ฆฌ์ฅฌ์ฌ OKR/์์ ์์ ๋ชจ์/` 4๊ฐ ์๋ ๋ถ์
python cli_test.py path.mp4 # ํน์ ํ์ผ๋ง
python cli_test.py path.mp4 --focus "..." # ์ง์ค ๋ถ์ ์ง๋ฌธ ์ถ๊ฐ (7๋ฒ ์นดํ
๊ณ ๋ฆฌ)
python cli_test.py --focus "PDRN ๋๋๊ฐ ๋์ค๋?" # 4๊ฐ ๋ชจ๋ ๋์ผ ์ง๋ฌธ์ผ๋ก
"""
from __future__ import annotations
import os
import sys
import tempfile
from pathlib import Path
# ํ๋ก์ ํธ ๋ฃจํธ ๊ฒฝ๋ก ์ถ๊ฐ
ROOT = Path(__file__).resolve().parent
sys.path.insert(0, str(ROOT))
import schema
import pipeline
DEFAULT_VIDEO_DIR = ROOT.parent / "์์ ์์ ๋ชจ์"
def _load_secrets() -> str | None:
"""ํ๊ฒฝ๋ณ์ โ .streamlit/secrets.toml ์์ผ๋ก API ํค ๋ก๋."""
key = os.environ.get("ANTHROPIC_API_KEY")
if key:
return key
secrets_path = ROOT / ".streamlit" / "secrets.toml"
if secrets_path.exists():
# toml ํ์ฑ (๊ฐ๋จ)
for line in secrets_path.read_text(encoding="utf-8").splitlines():
line = line.strip()
if line.startswith("ANTHROPIC_API_KEY"):
_, _, v = line.partition("=")
v = v.strip().strip('"').strip("'")
if v and not v.startswith("sk-ant-์ฌ๊ธฐ์"):
return v
return None
def _print_progress(label: str, pct: float) -> None:
bar = "โ" * int(pct * 30) + "โ" * (30 - int(pct * 30))
print(f" [{bar}] {pct*100:5.1f}% โ {label}")
def analyze_file(client, mp4: Path, focus_question: str | None = None) -> None:
print(f"\n{'โ'*70}")
print(f"โถ ๋ถ์: {mp4.name}")
if focus_question:
print(f" ์ง์ค ์ง๋ฌธ: {focus_question}")
print(f"{'โ'*70}")
with tempfile.TemporaryDirectory(prefix="reelsbench_cli_") as tmp:
try:
a = pipeline.run_pipeline(
client=client,
input_source=mp4,
workdir_root=Path(tmp),
keep_mp4=False,
progress=_print_progress,
focus_question=focus_question,
)
except Exception as e:
print(f"โ ์คํจ: {e}")
import traceback; traceback.print_exc()
return
print(f"\nโ
video_id={a.video_id}")
print(f" ๋น์ฉ: ${a.cost_usd:.4f}")
print(f" ๊ฒ์ฆ ์คํจ: {a.verification_failed_count}๊ฑด")
print(f"\n๐ ์นดํ
๊ณ ๋ฆฌ ์์ฝ:")
print(f" 1. ์ ํ/๋ธ๋๋: {len(a.products)}๊ฑด")
print(f" 2. ์๊ตฌ ํจ๋ฅ: {len(a.efficacy_claims)}๊ฑด")
print(f" 3. ํต์ฌ ์ฑ๋ถ: {len(a.ingredients)}๊ฑด")
print(f" 4. ํํน ํฌ์ธํธ: {len(a.hooks)}๊ฑด")
print(f" 5. ํ์ /๋ฉ์ปค๋์ฆ: {len(a.science)}๊ฑด")
print(f" 6. ํ๊น & ํค: {len(a.audiences)}๊ฑด")
if a.focus_answer:
fa = a.focus_answer
print(f" 7. ์ง์ค ํฌ์ธํธ: {'๋ต๋ณ ์์' if fa.get('stated_in_video') else '์์์์ ๋ต์ ๋ชป ์ฐพ์'}")
# ์์ธํ ์ถ๋ ฅ
for cat_name, items in [
("์ ํ", a.products), ("ํจ๋ฅ", a.efficacy_claims), ("์ฑ๋ถ", a.ingredients),
("ํํน", a.hooks), ("ํ์ ", a.science), ("ํ๊น", a.audiences),
]:
if not items:
continue
print(f"\n [{cat_name}]")
for it in items:
conf = it.get("confidence", 0)
print(f" ยท conf={conf:.2f} eid={it.get('evidence_id')} โ {it}")
if a.focus_answer:
fa = a.focus_answer
print(f"\n [์ง์ค ํฌ์ธํธ 7๋ฒ]")
print(f" Q: {a.focus_question}")
print(f" A: {fa.get('answer')}")
print(f" ๊ทผ๊ฑฐ evidence_ids: {fa.get('evidence_ids')} (conf={fa.get('confidence'):.2f})")
for q in (fa.get("key_quotes") or []):
print(f" \"{q}\"")
def main():
key = _load_secrets()
if not key:
print("โ ANTHROPIC_API_KEY ์ค์ ์ ๋จ.")
print(" .streamlit/secrets.toml ๋๋ ํ๊ฒฝ๋ณ์์ ์ค์ ํ ์ฌ์คํ.")
sys.exit(1)
from anthropic import Anthropic
client = Anthropic(api_key=key)
# --focus "..." ํ์ฑ (๊ฐ๋จํ ์ธ์ ์ฒ๋ฆฌ)
focus_question: str | None = None
raw_args = sys.argv[1:]
cleaned_args: list[str] = []
i = 0
while i < len(raw_args):
if raw_args[i] == "--focus" and i + 1 < len(raw_args):
focus_question = raw_args[i + 1]
i += 2
else:
cleaned_args.append(raw_args[i])
i += 1
if cleaned_args:
targets = [Path(a) for a in cleaned_args]
else:
if not DEFAULT_VIDEO_DIR.exists():
print(f"โ ๊ธฐ๋ณธ ์์ ํด๋ ์์: {DEFAULT_VIDEO_DIR}")
sys.exit(1)
targets = sorted([p for p in DEFAULT_VIDEO_DIR.glob("*.mp4")])
if not targets:
print(f"โ {DEFAULT_VIDEO_DIR} ์์ .mp4 ํ์ผ ์์.")
sys.exit(1)
print(f"๐ฌ reels-bench CLI ํ
์คํธ โ {len(targets)}๊ฐ ์์")
print(f" ๋ชจ๋ธ: {schema.HAIKU_MODEL} (Pass 1) + {schema.SONNET_MODEL} (Pass 2)")
if focus_question:
print(f" ์ง์ค ์ง๋ฌธ: {focus_question}")
for mp4 in targets:
analyze_file(client, mp4, focus_question=focus_question)
print(f"\n{'โ'*70}")
print("โ
์ ์ฒด ์๋ฃ. Streamlit์ผ๋ก ๊ฒฐ๊ณผ ๋ณด๊ธฐ: `streamlit run app.py`")
if __name__ == "__main__":
main()
|