Abhishek279 commited on
Commit
3baf1b7
·
verified ·
1 Parent(s): 0592e7f

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +54 -46
src/streamlit_app.py CHANGED
@@ -1279,37 +1279,46 @@ if uploaded_file is not None:
1279
  aligned_segments = align_transcription_with_speakers(result["segments"], speaker_segments)
1280
 
1281
  # SECOND-BY-SECOND SENTIMENT ANALYSIS
1282
- st.subheader("📊 Second-by-Second Sentiment Analysis")
 
1283
 
1284
- # 1. Text Sentiment Analysis (Second-by-Second)
1285
  text_sentiment_per_second = []
1286
- if sentiment_analyzer:
1287
- with st.spinner("Analyzing text sentiment second-by-second..."):
1288
- text_sentiment_per_second = analyze_text_sentiment_second_by_second(
1289
- result["segments"],
1290
- sentiment_analyzer,
1291
- video_duration
1292
- )
1293
-
1294
- # 2. Audio Tone Sentiment Analysis (Second-by-Second)
1295
  audio_sentiment_per_second = []
1296
- if audio_sentiment_analyzer:
1297
- with st.spinner("Analyzing audio tone sentiment second-by-second (based on voice tone, not words)..."):
1298
- audio_sentiment_per_second = analyze_audio_sentiment_second_by_second(
1299
- tmp_video_path,
1300
- audio_sentiment_analyzer,
1301
- video_duration
1302
- )
1303
-
1304
- # 3. Visual Sentiment Analysis (Second-by-Second)
1305
  visual_sentiment_per_second = []
1306
- if visual_sentiment_analyzer:
1307
- with st.spinner("Analyzing visual sentiment second-by-second from facial expressions..."):
1308
- visual_sentiment_per_second = analyze_visual_sentiment_second_by_second(
1309
- tmp_video_path,
1310
- visual_sentiment_analyzer,
1311
- video_duration
1312
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1313
 
1314
  # Create and display timeline graphs
1315
  if text_sentiment_per_second or audio_sentiment_per_second or visual_sentiment_per_second:
@@ -1323,17 +1332,20 @@ if uploaded_file is not None:
1323
  )
1324
 
1325
  # Display graphs
1326
- if fig_text:
1327
- st.pyplot(fig_text)
1328
- plt.close(fig_text)
1329
-
1330
- if fig_audio:
1331
- st.pyplot(fig_audio)
1332
- plt.close(fig_audio)
1333
-
1334
- if fig_visual:
1335
- st.pyplot(fig_visual)
1336
- plt.close(fig_visual)
 
 
 
1337
 
1338
  # Summary statistics
1339
  st.markdown("### 📊 Sentiment Summary")
@@ -1360,16 +1372,12 @@ if uploaded_file is not None:
1360
  visual_neu = sum(1 for s in visual_sentiment_per_second if s["sentiment"] == "NEUTRAL")
1361
  st.metric("🎥 Visual Sentiment", f"Pos: {visual_pos}s | Neg: {visual_neg}s | Neu: {visual_neu}s")
1362
 
1363
- # Legacy emotion analysis (keep for backward compatibility)
1364
  visual_emotions = []
1365
- if visual_emotion_analyzer:
1366
- with st.spinner("Analyzing emotions from video frames..."):
1367
- visual_emotions = analyze_visual_emotions(tmp_video_path, visual_emotion_analyzer, max_frames=30)
1368
-
1369
  audio_tone_result = None
1370
- if audio_emotion_analyzer:
1371
- with st.spinner("Analyzing audio tone and prosody..."):
1372
- audio_tone_result = analyze_audio_tone_emotions(tmp_video_path, audio_emotion_analyzer)
1373
 
1374
  # Display results
1375
  # Main transcription text
 
1279
  aligned_segments = align_transcription_with_speakers(result["segments"], speaker_segments)
1280
 
1281
  # SECOND-BY-SECOND SENTIMENT ANALYSIS
1282
+ # Skip for very long videos to avoid timeout
1283
+ MAX_VIDEO_DURATION_FOR_DETAILED_ANALYSIS = 300 # 5 minutes
1284
 
 
1285
  text_sentiment_per_second = []
 
 
 
 
 
 
 
 
 
1286
  audio_sentiment_per_second = []
 
 
 
 
 
 
 
 
 
1287
  visual_sentiment_per_second = []
1288
+
1289
+ if video_duration > 0 and video_duration <= MAX_VIDEO_DURATION_FOR_DETAILED_ANALYSIS:
1290
+ st.subheader("📊 Second-by-Second Sentiment Analysis")
1291
+
1292
+ # 1. Text Sentiment Analysis (Second-by-Second)
1293
+ if sentiment_analyzer:
1294
+ with st.spinner("Analyzing text sentiment second-by-second..."):
1295
+ try:
1296
+ text_sentiment_per_second = analyze_text_sentiment_second_by_second(
1297
+ result["segments"],
1298
+ sentiment_analyzer,
1299
+ video_duration
1300
+ )
1301
+ except Exception as e:
1302
+ st.warning(f"⚠️ Text sentiment analysis skipped: {str(e)}")
1303
+
1304
+ # 2. Audio Tone Sentiment Analysis (Second-by-Second)
1305
+ if audio_sentiment_analyzer:
1306
+ with st.spinner("Analyzing audio tone sentiment second-by-second..."):
1307
+ try:
1308
+ audio_sentiment_per_second = analyze_audio_sentiment_second_by_second(
1309
+ tmp_video_path,
1310
+ audio_sentiment_analyzer,
1311
+ video_duration
1312
+ )
1313
+ except Exception as e:
1314
+ st.warning(f"⚠️ Audio sentiment analysis skipped: {str(e)}")
1315
+
1316
+ # 3. Visual Sentiment Analysis (Second-by-Second) - SKIP for performance
1317
+ # This is very slow, disable it
1318
+ st.info("ℹ️ Visual sentiment analysis disabled for faster processing")
1319
+
1320
+ elif video_duration > MAX_VIDEO_DURATION_FOR_DETAILED_ANALYSIS:
1321
+ st.info(f"ℹ️ Video is {video_duration:.0f}s long. Second-by-second analysis is disabled for videos longer than {MAX_VIDEO_DURATION_FOR_DETAILED_ANALYSIS}s to prevent timeout.")
1322
 
1323
  # Create and display timeline graphs
1324
  if text_sentiment_per_second or audio_sentiment_per_second or visual_sentiment_per_second:
 
1332
  )
1333
 
1334
  # Display graphs
1335
+ try:
1336
+ if fig_text:
1337
+ st.pyplot(fig_text)
1338
+ plt.close(fig_text)
1339
+
1340
+ if fig_audio:
1341
+ st.pyplot(fig_audio)
1342
+ plt.close(fig_audio)
1343
+
1344
+ if fig_visual:
1345
+ st.pyplot(fig_visual)
1346
+ plt.close(fig_visual)
1347
+ except Exception as e:
1348
+ st.warning(f"⚠️ Could not display graphs: {str(e)}")
1349
 
1350
  # Summary statistics
1351
  st.markdown("### 📊 Sentiment Summary")
 
1372
  visual_neu = sum(1 for s in visual_sentiment_per_second if s["sentiment"] == "NEUTRAL")
1373
  st.metric("🎥 Visual Sentiment", f"Pos: {visual_pos}s | Neg: {visual_neg}s | Neu: {visual_neu}s")
1374
 
1375
+ # Legacy emotion analysis (DISABLED for performance - too slow)
1376
  visual_emotions = []
 
 
 
 
1377
  audio_tone_result = None
1378
+
1379
+ # Skip these for faster processing
1380
+ st.info("ℹ️ Visual and audio emotion analysis disabled for faster results. Focus on transcription and text sentiment.")
1381
 
1382
  # Display results
1383
  # Main transcription text