iisadia commited on
Commit
4a0eb2e
·
verified ·
1 Parent(s): 8b5587b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -28,10 +28,16 @@ def process_audio(audio_bytes):
28
  return {"raw": waveform.numpy().squeeze(), "sampling_rate": 16000}
29
 
30
  # Voice input component
 
31
  def voice_input(key, prompt_text, default_text=""):
 
 
 
 
32
  col1, col2 = st.columns([4, 1])
33
  with col1:
34
- text_input = st.text_input(prompt_text, value=default_text, key=f"text_{key}")
 
35
  with col2:
36
  audio_bytes = audio_recorder(
37
  pause_threshold=0.8,
@@ -51,15 +57,15 @@ def voice_input(key, prompt_text, default_text=""):
51
  whisper = load_model()
52
  transcribed_text = whisper(audio_input)["text"]
53
 
54
- # Update the corresponding text input
55
  st.session_state[f"text_{key}"] = transcribed_text
56
  st.rerun()
57
 
58
  except Exception as e:
59
  st.error(f"Error in voice input: {str(e)}")
60
 
61
- return text_input
62
-
63
  # Enhanced Custom CSS with modern design
64
  def inject_custom_css():
65
  st.markdown("""
 
28
  return {"raw": waveform.numpy().squeeze(), "sampling_rate": 16000}
29
 
30
  # Voice input component
31
+ # Updated voice_input function
32
  def voice_input(key, prompt_text, default_text=""):
33
+ # Initialize session state keys if they don't exist
34
+ if f"text_{key}" not in st.session_state:
35
+ st.session_state[f"text_{key}"] = default_text
36
+
37
  col1, col2 = st.columns([4, 1])
38
  with col1:
39
+ # Create the text input with the current session state value
40
+ text_value = st.text_input(prompt_text, value=st.session_state[f"text_{key}"], key=f"text_input_{key}")
41
  with col2:
42
  audio_bytes = audio_recorder(
43
  pause_threshold=0.8,
 
57
  whisper = load_model()
58
  transcribed_text = whisper(audio_input)["text"]
59
 
60
+ # Update the session state value (this happens before widget creation)
61
  st.session_state[f"text_{key}"] = transcribed_text
62
  st.rerun()
63
 
64
  except Exception as e:
65
  st.error(f"Error in voice input: {str(e)}")
66
 
67
+ # Return the current text value (from either manual input or voice)
68
+ return st.session_state[f"text_{key}"]
69
  # Enhanced Custom CSS with modern design
70
  def inject_custom_css():
71
  st.markdown("""