NickVerri commited on
Commit
4b2ca68
·
verified ·
1 Parent(s): 6449789

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -6
app.py CHANGED
@@ -196,7 +196,7 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset=0.0)
196
  clip_note = (raw_note[:75] + '..') if len(raw_note) > 75 else raw_note
197
 
198
  lines.append(f'\t\t\t\t<clipitem id="clipitem-v-{i}">')
199
- lines.append(f'\t\t\t\t\t<name>{source_name}</name>')
200
  lines.append(f'\t\t\t\t\t<duration>8640000</duration>')
201
  lines.append(f'\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
202
  lines.append(f'\t\t\t\t\t<start>{tl_start}</start>')
@@ -265,7 +265,7 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset=0.0)
265
  lines.append(f'\t\t\t\t\t<end>{tl_end}</end>')
266
  lines.append(f'\t\t\t\t\t<in>{src_in_frames}</in>')
267
  lines.append(f'\t\t\t\t\t<out>{src_out_frames}</out>')
268
- lines.append(f'\t\t\t\t\t<file id="{master_id}"/>')
269
  lines.append('\t\t\t\t\t<sourcetrack><mediatype>audio</mediatype><trackindex>1</trackindex></sourcetrack>')
270
  lines.append('\t\t\t\t</clipitem>')
271
  timeline_head_frames = tl_end + seconds_to_frames(float(seg.get('gap', 0.0)), fps)
@@ -278,6 +278,23 @@ def generate_xml(sequence_name, segments, source_name, fps=25, start_offset=0.0)
278
 
279
  return "\n".join(lines)
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  def call_gemini_for_edl(transcript_data, story_prompt, api_key):
282
  if not api_key:
283
  st.error("Gemini API Key is missing.")
@@ -318,12 +335,12 @@ def call_gemini_for_edl(transcript_data, story_prompt, api_key):
318
  "Content-Type": "application/json"
319
  }
320
 
321
- # Cascading Fallback List - If one fails, it instantly tries the next.
322
  models_to_try = [
323
  "gemini-2.5-flash",
324
- "gemini-3.1-flash",
325
- "gemini-1.5-flash",
326
- "gemini-2.5-pro"
327
  ]
328
 
329
  # Try the v1beta endpoint first as it natively supports systemInstruction and responseMimeType in REST
@@ -436,6 +453,20 @@ with st.sidebar:
436
  placeholder="e.g. Interview_Day1_Multi",
437
  help=input_help
438
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
 
440
  uploaded_file = st.file_uploader("Upload Video/Audio Clip", type=["mp4", "m4a", "wav", "mp3", "mov"])
441
 
 
196
  clip_note = (raw_note[:75] + '..') if len(raw_note) > 75 else raw_note
197
 
198
  lines.append(f'\t\t\t\t<clipitem id="clipitem-v-{i}">')
199
+ lines.append(f'\t\t\t\t\t<name>{source_name}</name>') # Conform fix: matching source
200
  lines.append(f'\t\t\t\t\t<duration>8640000</duration>')
201
  lines.append(f'\t\t\t\t\t<rate><timebase>{timebase}</timebase></rate>')
202
  lines.append(f'\t\t\t\t\t<start>{tl_start}</start>')
 
265
  lines.append(f'\t\t\t\t\t<end>{tl_end}</end>')
266
  lines.append(f'\t\t\t\t\t<in>{src_in_frames}</in>')
267
  lines.append(f'\t\t\t\t\t<out>{src_out_frames}</out>')
268
+ lines.append(f'\t\t\t\t\t<file id="{master_id}"/>') # Conform fix: link to audio file properly
269
  lines.append('\t\t\t\t\t<sourcetrack><mediatype>audio</mediatype><trackindex>1</trackindex></sourcetrack>')
270
  lines.append('\t\t\t\t</clipitem>')
271
  timeline_head_frames = tl_end + seconds_to_frames(float(seg.get('gap', 0.0)), fps)
 
278
 
279
  return "\n".join(lines)
280
 
281
+ def get_available_models(api_key):
282
+ """Fetches the list of valid models for the provided API key."""
283
+ if not api_key:
284
+ return "No API key provided."
285
+ url = f"https://generativelanguage.googleapis.com/v1beta/models?key={api_key}"
286
+ try:
287
+ res = requests.get(url)
288
+ if res.status_code == 200:
289
+ models = res.json().get('models', [])
290
+ # Filter for models that support generateContent
291
+ gen_models = [m['name'].replace('models/', '') for m in models if 'generateContent' in m.get('supportedGenerationMethods', [])]
292
+ return gen_models
293
+ else:
294
+ return f"Error {res.status_code}: {res.text}"
295
+ except Exception as e:
296
+ return f"Error connecting to API: {e}"
297
+
298
  def call_gemini_for_edl(transcript_data, story_prompt, api_key):
299
  if not api_key:
300
  st.error("Gemini API Key is missing.")
 
335
  "Content-Type": "application/json"
336
  }
337
 
338
+ # Cascading Fallback List perfectly mapped to the valid, stable models output from the v1 API token!
339
  models_to_try = [
340
  "gemini-2.5-flash",
341
+ "gemini-2.5-pro",
342
+ "gemini-2.5-flash-lite",
343
+ "gemini-2.0-flash"
344
  ]
345
 
346
  # Try the v1beta endpoint first as it natively supports systemInstruction and responseMimeType in REST
 
453
  placeholder="e.g. Interview_Day1_Multi",
454
  help=input_help
455
  )
456
+
457
+ st.divider()
458
+ st.info("🛠️ **Debug Tools**")
459
+ if st.button("🔍 Check Available Gemini Models"):
460
+ if not ACTIVE_GEMINI_KEY:
461
+ st.error("Please provide a Gemini API Key in secrets or environment.")
462
+ else:
463
+ with st.spinner("Asking Google for your available models..."):
464
+ models = get_available_models(ACTIVE_GEMINI_KEY)
465
+ if isinstance(models, list):
466
+ st.success(f"Found {len(models)} models that support text generation!")
467
+ st.json(models)
468
+ else:
469
+ st.error(models)
470
 
471
  uploaded_file = st.file_uploader("Upload Video/Audio Clip", type=["mp4", "m4a", "wav", "mp3", "mov"])
472