Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)
Python
Show detailed math for input token calculation
Abi Rajac380aa3bff60
diff --git a/backend/models/gemini.py b/backend/models/gemini.pyindex 8d7ac18f..e5028739 100644--- a/backend/models/gemini.py+++ b/backend/models/gemini.py@@ -9,6 +9,7 @@ from video.cost_estimation import (calculate_cost,estimate_video_generation_cost,format_cost_estimate,+ format_detailed_input_estimate,get_video_duration_from_bytes,MediaResolution,)@@ -316,8 +317,9 @@ async def stream_gemini_response_video(thinking_level=thinking_level,)print(f"\n=== Video Generation Cost Estimate ({model.value}) ===")- print(f"Video duration: {video_duration:.2f} seconds")- print(format_cost_estimate(estimated_cost))+ print(format_detailed_input_estimate(video_duration, MediaResolution.HIGH, model))+ print(f"Output tokens (est): {estimated_cost.output_tokens:,} (${estimated_cost.output_cost:.4f})")+ print(f"Total estimated cost: ${estimated_cost.total_cost:.4f}")print("=" * 50)else:print("Warning: Could not determine video duration for cost estimation")diff --git a/backend/video/cost_estimation.py b/backend/video/cost_estimation.pyindex fdf014e2..2324cb42 100644--- a/backend/video/cost_estimation.py+++ b/backend/video/cost_estimation.py@@ -160,6 +160,28 @@ def format_cost_estimate(cost: CostEstimate) -> str:)+def format_detailed_input_estimate(+ video_duration_seconds: float,+ media_resolution: MediaResolution,+ model: Llm,+) -> str:+ tokens_per_second = VIDEO_TOKENS_PER_SECOND[media_resolution]+ video_tokens = int(video_duration_seconds * tokens_per_second)+ total_input_tokens = video_tokens + PROMPT_TOKENS_ESTIMATE++ model_name = get_model_api_name(model)+ pricing = GEMINI_PRICING.get(model_name, GEMINI_PRICING["gemini-3-flash-preview"])+ input_cost = (total_input_tokens / 1_000_000) * pricing["input_per_million"]++ return (+ f"Input Token Calculation:\n"+ f" Video: {video_duration_seconds:.2f}s × {tokens_per_second} tokens/s = {video_tokens:,} tokens\n"+ f" Prompt overhead: {PROMPT_TOKENS_ESTIMATE:,} tokens\n"+ f" Total input: {total_input_tokens:,} tokens\n"+ f" Cost: {total_input_tokens:,} ÷ 1M × ${pricing['input_per_million']:.2f} = ${input_cost:.4f}"+ )++def get_video_duration_from_bytes(video_bytes: bytes) -> float | None:try:import tempfile