Spaces:
Sleeping
Sleeping
Download cli_test.py from neosimHan/reels-bench: direct link, hf CLI and curl.
- Browser
- Download file 5.5 kB
-
https://huggingface.co/spaces/neosimHan/reels-bench/resolve/main/cli_test.py
- Command line
-
hf download hf://spaces/neosimHan/reels-bench/cli_test.py
-
curl -L -o cli_test.py https://huggingface.co/spaces/neosimHan/reels-bench/resolve/main/cli_test.py
5.5 kB
| """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() | |