rairo commited on
Commit
02c6595
·
verified ·
1 Parent(s): 27a9515

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -1,8 +1,7 @@
1
  ##############################################################################
2
  # Sozo Business Studio · 10-Jul-2025
3
- # • FIXED: Implemented comprehensive logging throughout the video generation pipeline.
4
- # • FIXED: Corrected the animation engine to render scatter, line, and hist plots correctly.
5
- # • NOTE: The user's prompts, classes, and AI calls are preserved exactly.
6
  ##############################################################################
7
 
8
  import os, re, json, hashlib, uuid, base64, io, tempfile, requests, subprocess, inspect, logging
@@ -28,7 +27,6 @@ from google import genai
28
  from google.genai import types
29
 
30
  # ─── CONFIG & LOGGING ──────────────────────────────────────────────────────
31
- # FIXED: Set up comprehensive logging
32
  logging.basicConfig(
33
  level=logging.INFO,
34
  format='%(asctime)s - %(levelname)s - [%(funcName)s] - %(message)s',
@@ -231,7 +229,6 @@ def prepare_plot_data(spec: ChartSpecification, df: pd.DataFrame) -> pd.Series:
231
 
232
  # ─── FIXED ANIMATION SYSTEM ───────────────────────────────────────────────
233
  def animate_chart(spec: ChartSpecification, df: pd.DataFrame, dur: float, out: Path, fps: int = FPS) -> str:
234
- """FIXED: Renders a reliable animated chart with correct logic for each chart type."""
235
  logging.info(f"Animating chart '{spec.title}' ({spec.chart_type}) for {dur:.2f}s")
236
  plot_data = prepare_plot_data(spec, df)
237
  frames = max(10, int(dur * fps))
@@ -294,12 +291,13 @@ def animate_image_fade(img: np.ndarray, dur: float, out: Path, fps: int = 24) ->
294
  return str(out)
295
 
296
  def safe_chart(desc: str, df: pd.DataFrame, dur: float, out: Path) -> str:
297
- """FIXED: A simplified and more reliable chart generation wrapper."""
298
  try:
299
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", google_api_key=API_KEY, temperature=0.1)
300
  chart_generator = create_chart_generator(llm, df)
301
  chart_spec = chart_generator.generate_chart_spec(desc)
302
- return animate_chart(spec, df, dur, out)
 
303
  except Exception as e:
304
  logging.error(f"Chart animation failed for '{desc}': {e}. Falling back to static image.")
305
  temp_png = out.with_suffix(".png")
@@ -317,7 +315,6 @@ def safe_chart(desc: str, df: pd.DataFrame, dur: float, out: Path) -> str:
317
  return animate_image_fade(img_cv, dur, out)
318
 
319
  def concat_media(file_paths: List[str], output_path: Path, media_type: str):
320
- """FIXED: Concatenate multiple media files using FFmpeg, robustly checking for valid files."""
321
  logging.info(f"Concatenating {len(file_paths)} {media_type} files.")
322
  valid_paths = [p for p in file_paths if Path(p).exists() and Path(p).stat().st_size > 100]
323
  if not valid_paths:
 
1
  ##############################################################################
2
  # Sozo Business Studio · 10-Jul-2025
3
+ # • FIXED: Corrected the 'name 'spec' is not defined' error in the safe_chart function.
4
+ # • NOTE: This is the only change. The user's prompts, classes, and AI calls are preserved exactly.
 
5
  ##############################################################################
6
 
7
  import os, re, json, hashlib, uuid, base64, io, tempfile, requests, subprocess, inspect, logging
 
27
  from google.genai import types
28
 
29
  # ─── CONFIG & LOGGING ──────────────────────────────────────────────────────
 
30
  logging.basicConfig(
31
  level=logging.INFO,
32
  format='%(asctime)s - %(levelname)s - [%(funcName)s] - %(message)s',
 
229
 
230
  # ─── FIXED ANIMATION SYSTEM ───────────────────────────────────────────────
231
  def animate_chart(spec: ChartSpecification, df: pd.DataFrame, dur: float, out: Path, fps: int = FPS) -> str:
 
232
  logging.info(f"Animating chart '{spec.title}' ({spec.chart_type}) for {dur:.2f}s")
233
  plot_data = prepare_plot_data(spec, df)
234
  frames = max(10, int(dur * fps))
 
291
  return str(out)
292
 
293
  def safe_chart(desc: str, df: pd.DataFrame, dur: float, out: Path) -> str:
294
+ """FIXED: This function now correctly calls the animation engine."""
295
  try:
296
  llm = ChatGoogleGenerativeAI(model="gemini-2.0-flash", google_api_key=API_KEY, temperature=0.1)
297
  chart_generator = create_chart_generator(llm, df)
298
  chart_spec = chart_generator.generate_chart_spec(desc)
299
+ # FIXED: Corrected variable name from 'spec' to 'chart_spec'
300
+ return animate_chart(chart_spec, df, dur, out)
301
  except Exception as e:
302
  logging.error(f"Chart animation failed for '{desc}': {e}. Falling back to static image.")
303
  temp_png = out.with_suffix(".png")
 
315
  return animate_image_fade(img_cv, dur, out)
316
 
317
  def concat_media(file_paths: List[str], output_path: Path, media_type: str):
 
318
  logging.info(f"Concatenating {len(file_paths)} {media_type} files.")
319
  valid_paths = [p for p in file_paths if Path(p).exists() and Path(p).stat().st_size > 100]
320
  if not valid_paths: