gholapeajinkya commited on
Commit
96eda52
Β·
verified Β·
1 Parent(s): df1c060

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +67 -30
app.py CHANGED
@@ -43,6 +43,7 @@ import sys
43
  import torch
44
  import pandas as pd
45
  import streamlit as st
 
46
 
47
  print("Streamlit config dir:", os.environ.get("STREAMLIT_CONFIG_DIR"))
48
 
@@ -365,6 +366,20 @@ def seconds_to_srt_time(seconds):
365
  milliseconds = int((seconds % 1) * 1000)
366
  return f"{hours:02d}:{minutes:02d}:{secs:02d},{milliseconds:03d}"
367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
  # Main Streamlit app
369
  if __name__ == "__main__":
370
  if "is_processing" not in st.session_state:
@@ -570,34 +585,56 @@ if __name__ == "__main__":
570
 
571
  st.subheader("πŸ“Ί Demo Videos")
572
 
573
- # Check if sample videos exist and display them
574
- demo_videos = [
575
- ("sample_input_video.mp4", "Original Japanese video πŸ‡―πŸ‡΅"),
576
- ("dubbed_video_large_english.mp4", "Japanese to English Dub πŸ‡―πŸ‡΅βž‘οΈπŸ‡ΊπŸ‡Έ"),
577
- ("dubbed_video_large_chinese.mp4", "Japanese to Chinese Dub πŸ‡―πŸ‡΅βž‘οΈπŸ‡¨πŸ‡³"),
578
- ]
579
-
580
- demo_cols = st.columns(len(demo_videos))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
581
 
582
- for i, (video_file, title) in enumerate(demo_videos):
583
- video_path = os.path.join(demo_dir, video_file)
584
- if os.path.exists(video_path):
585
- with demo_cols[i]:
586
- st.markdown(f"**{title}**")
587
- st.video(video_path)
588
- else:
589
- with demo_cols[i]:
590
- st.markdown(f"**{title}**")
591
- st.info("Demo video will appear")
592
-
593
- st.markdown("---")
594
-
595
- if os.path.exists(os.path.join(demo_dir, "output_segments_large_english.csv")):
596
- st.subheader("πŸ“Š Sample Transcription Results")
597
- try:
598
- sample_df = pd.read_csv(os.path.join(
599
- demo_dir, "output_segments_large_english.csv"))
600
- st.dataframe(sample_df.head(
601
- 10), use_container_width=True, hide_index=True)
602
- except Exception as e:
603
- st.info("Sample transcription data will appear here")
 
43
  import torch
44
  import pandas as pd
45
  import streamlit as st
46
+ import json
47
 
48
  print("Streamlit config dir:", os.environ.get("STREAMLIT_CONFIG_DIR"))
49
 
 
366
  milliseconds = int((seconds % 1) * 1000)
367
  return f"{hours:02d}:{minutes:02d}:{secs:02d},{milliseconds:03d}"
368
 
369
+ def load_demo_data():
370
+ """Load demo data from demo.json file"""
371
+ demo_json_path = os.path.join(demo_dir, "demo.json")
372
+ try:
373
+ with open(demo_json_path, 'r', encoding='utf-8') as f:
374
+ return json.load(f)
375
+ except FileNotFoundError:
376
+ st.error(f"Demo file not found: {demo_json_path}")
377
+ return []
378
+ except json.JSONDecodeError as e:
379
+ st.error(f"Error reading demo file: {e}")
380
+ return []
381
+
382
+
383
  # Main Streamlit app
384
  if __name__ == "__main__":
385
  if "is_processing" not in st.session_state:
 
585
 
586
  st.subheader("πŸ“Ί Demo Videos")
587
 
588
+ # Load demo data from JSON
589
+ demo_data = load_demo_data()
590
+
591
+ if demo_data:
592
+ for i, demo in enumerate(demo_data):
593
+ # Create columns for videos
594
+ if demo['videos']:
595
+ with st.expander(f"Demo {i + 1}", expanded=True):
596
+ demo_videos = st.columns(len(demo['videos']))
597
+
598
+ for j, video_info in enumerate(demo['videos']):
599
+ video_id = video_info['id']
600
+ video_name = video_info['name']
601
+
602
+ # Construct video path based on demo structure
603
+ video_path = os.path.join(
604
+ demo_dir, demo['id'], 'videos', video_id, 'video.mp4')
605
+
606
+ with demo_videos[j]:
607
+ st.markdown(f"**{video_name}**")
608
+
609
+ if os.path.exists(video_path):
610
+ st.video(video_path)
611
+ else:
612
+ st.info("Video will appear here")
613
+
614
+ # Create columns for transcriptions if they exist
615
+ videos_with_transcriptions = [v for v in demo['videos'] if 'transcription_url' in v]
616
+
617
+ if videos_with_transcriptions:
618
+ st.markdown("### πŸ“Š Transcription Results")
619
+ transcription_cols = st.columns(len(videos_with_transcriptions))
620
+
621
+ for k, video_info in enumerate(videos_with_transcriptions):
622
+ video_id = video_info['id']
623
+ video_name = video_info['name']
624
+
625
+ # Construct transcription path
626
+ transcription_path = os.path.join(
627
+ demo_dir, demo['id'], 'videos', video_id, 'transcription.csv')
628
+
629
+ with transcription_cols[k]:
630
+ st.markdown(f"**{video_name} - Transcription**")
631
+
632
+ if os.path.exists(transcription_path):
633
+ try:
634
+ transcription_df = pd.read_csv(transcription_path)
635
+ st.dataframe(transcription_df, use_container_width=True, hide_index=True, height=400)
636
+ except Exception as e:
637
+ st.error(f"Error loading transcription: {e}")
638
+ else:
639
+ st.info("Transcription will appear here")
640