Garvitj commited on
Commit
92a6cf4
·
verified ·
1 Parent(s): 5442d6b

Update src/app.py

Browse files
Files changed (1) hide show
  1. src/app.py +11 -7
src/app.py CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
2
  import cv2
3
  import numpy as np
4
  import os
5
- import tempfile # <-- 1. IMPORT TEMPFILE
6
  from dotenv import load_dotenv
7
  from st_audiorec import st_audiorec
8
  from analysis import (
@@ -42,6 +42,16 @@ with col1:
42
  st.subheader("📸 1. Capture Your Expression")
43
  camera_image = st.camera_input("Take a snapshot")
44
 
 
 
 
 
 
 
 
 
 
 
45
  with col2:
46
  st.subheader("💭 2. Your Query")
47
  user_query = st.text_area(
@@ -75,12 +85,9 @@ if st.button("🧠 Analyze My Emotion & Answer", type="primary", use_container_w
75
  file_bytes = np.asarray(bytearray(camera_image.read()), dtype=np.uint8)
76
  image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
77
 
78
- # --- 2. USE A NAMED TEMPORARY FILE FOR THE IMAGE ---
79
  with tempfile.NamedTemporaryFile(delete=True, suffix=".jpg") as temp_img:
80
  cv2.imwrite(temp_img.name, image)
81
- # Pass the unique temp file's name for analysis
82
  facial_emotion = get_facial_emotion(temp_img.name)
83
- # The temp_img file is now automatically deleted
84
 
85
  except Exception as e:
86
  st.error(f"Error processing image: {e}")
@@ -89,14 +96,11 @@ if st.button("🧠 Analyze My Emotion & Answer", type="primary", use_container_w
89
  # Step 2: Process recorded audio
90
  with st.spinner("🎵 Saving and analyzing audio..."):
91
  try:
92
- # --- 3. USE A NAMED TEMPORARY FILE FOR THE AUDIO ---
93
  with tempfile.NamedTemporaryFile(delete=True, suffix=".wav") as temp_aud:
94
  temp_aud.write(audio_bytes)
95
 
96
- # Pass the unique temp file's name for analysis
97
  voice_emotion = get_voice_emotion(temp_aud.name)
98
  transcript = get_transcript(temp_aud.name)
99
- # The temp_aud file is now automatically deleted
100
 
101
  except Exception as e:
102
  st.error(f"Error processing audio: {e}")
 
2
  import cv2
3
  import numpy as np
4
  import os
5
+ import tempfile
6
  from dotenv import load_dotenv
7
  from st_audiorec import st_audiorec
8
  from analysis import (
 
42
  st.subheader("📸 1. Capture Your Expression")
43
  camera_image = st.camera_input("Take a snapshot")
44
 
45
+ # --- START: ADDED DEBUG BLOCK ---
46
+ # This block will re-run every time the app updates
47
+ if camera_image is None:
48
+ st.warning("DEBUG: 'camera_image' is currently None. Waiting for user to take photo...")
49
+ else:
50
+ st.success("DEBUG: Image captured!")
51
+ st.write(f"DEBUG: 'camera_image' has data. Type: {type(camera_image)}")
52
+ st.write(f"DEBUG: Image size: {camera_image.size} bytes")
53
+ # --- END: ADDED DEBUG BLOCK ---
54
+
55
  with col2:
56
  st.subheader("💭 2. Your Query")
57
  user_query = st.text_area(
 
85
  file_bytes = np.asarray(bytearray(camera_image.read()), dtype=np.uint8)
86
  image = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)
87
 
 
88
  with tempfile.NamedTemporaryFile(delete=True, suffix=".jpg") as temp_img:
89
  cv2.imwrite(temp_img.name, image)
 
90
  facial_emotion = get_facial_emotion(temp_img.name)
 
91
 
92
  except Exception as e:
93
  st.error(f"Error processing image: {e}")
 
96
  # Step 2: Process recorded audio
97
  with st.spinner("🎵 Saving and analyzing audio..."):
98
  try:
 
99
  with tempfile.NamedTemporaryFile(delete=True, suffix=".wav") as temp_aud:
100
  temp_aud.write(audio_bytes)
101
 
 
102
  voice_emotion = get_voice_emotion(temp_aud.name)
103
  transcript = get_transcript(temp_aud.name)
 
104
 
105
  except Exception as e:
106
  st.error(f"Error processing audio: {e}")