Gaurav vashistha commited on
Commit
256d59e
·
1 Parent(s): cd768cf

Fix Analysis Crash (List Handling) & Frontend Infinite Loop

Browse files
agent.py CHANGED
@@ -55,16 +55,18 @@ def analyze_only(path_a, path_c, job_id=None):
55
  "analysis_c": "Brief description of Video C's lighting, subject, and camera movement.",
56
  "visual_prompt_b": "A surreal, seamless morphing prompt that transforms A into C. DO NOT use words like 'dissolve' or 'cut'. Focus on shape and texture transformation."
57
  }
 
58
  """
59
  update_job_status(job_id, "analyzing", 30, "Director drafting creative morph...")
60
 
 
61
  res = client.models.generate_content(
62
  model="gemini-2.0-flash-exp",
63
  contents=[prompt, file_a, file_c],
64
  config=types.GenerateContentConfig(response_mime_type="application/json")
65
  )
66
 
67
- # FIX: Robust JSON Cleaning & List Handling
68
  text = res.text.strip()
69
  if text.startswith("```json"): text = text[7:]
70
  elif text.startswith("```"): text = text[3:]
@@ -85,6 +87,7 @@ def analyze_only(path_a, path_c, job_id=None):
85
  "prompt": text,
86
  "status": "success"
87
  }
 
88
  return {
89
  "analysis_a": data.get("analysis_a", ""),
90
  "analysis_c": data.get("analysis_c", ""),
 
55
  "analysis_c": "Brief description of Video C's lighting, subject, and camera movement.",
56
  "visual_prompt_b": "A surreal, seamless morphing prompt that transforms A into C. DO NOT use words like 'dissolve' or 'cut'. Focus on shape and texture transformation."
57
  }
58
+ DO NOT use markdown code blocks. Return RAW JSON only.
59
  """
60
  update_job_status(job_id, "analyzing", 30, "Director drafting creative morph...")
61
 
62
+ # Request JSON output
63
  res = client.models.generate_content(
64
  model="gemini-2.0-flash-exp",
65
  contents=[prompt, file_a, file_c],
66
  config=types.GenerateContentConfig(response_mime_type="application/json")
67
  )
68
 
69
+ # Robust JSON Cleaning
70
  text = res.text.strip()
71
  if text.startswith("```json"): text = text[7:]
72
  elif text.startswith("```"): text = text[3:]
 
87
  "prompt": text,
88
  "status": "success"
89
  }
90
+
91
  return {
92
  "analysis_a": data.get("analysis_a", ""),
93
  "analysis_c": data.get("analysis_c", ""),
stitch_continuity_dashboard/code.html CHANGED
@@ -357,6 +357,7 @@
357
  c.innerHTML = '<div class="text-center mt-10"><span class="material-symbols-outlined animate-spin">progress_activity</span></div>';
358
  try {
359
  const res = await fetch('/history');
 
360
  const data = await res.json();
361
  if (!data || !data.length) {
362
  c.innerHTML = '<div class="text-center text-gray-500 mt-10 text-xs">No history found.</div>';
@@ -412,6 +413,7 @@
412
  fd.append("video_c", fC);
413
  try {
414
  const res = await fetch("/analyze", { method: "POST", body: fd });
 
415
  const data = await res.json();
416
  document.getElementById("prompt-box").value = data.prompt;
417
 
@@ -450,6 +452,7 @@
450
  video_c_path: currentVideoCPath
451
  })
452
  });
 
453
  const data = await res.json();
454
  const poll = setInterval(async () => {
455
  const sRes = await fetch(`/status/${data.job_id}?t=${Date.now()}`);
 
357
  c.innerHTML = '<div class="text-center mt-10"><span class="material-symbols-outlined animate-spin">progress_activity</span></div>';
358
  try {
359
  const res = await fetch('/history');
360
+ if (!res.ok) throw new Error(res.statusText);
361
  const data = await res.json();
362
  if (!data || !data.length) {
363
  c.innerHTML = '<div class="text-center text-gray-500 mt-10 text-xs">No history found.</div>';
 
413
  fd.append("video_c", fC);
414
  try {
415
  const res = await fetch("/analyze", { method: "POST", body: fd });
416
+ if (!res.ok) throw new Error(res.statusText);
417
  const data = await res.json();
418
  document.getElementById("prompt-box").value = data.prompt;
419
 
 
452
  video_c_path: currentVideoCPath
453
  })
454
  });
455
+ if (!res.ok) throw new Error(res.statusText);
456
  const data = await res.json();
457
  const poll = setInterval(async () => {
458
  const sRes = await fetch(`/status/${data.job_id}?t=${Date.now()}`);