awacke1 commited on
Commit
62ff92d
โ€ข
1 Parent(s): 47d3d04

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -32
app.py CHANGED
@@ -217,21 +217,23 @@ def create_speech_component():
217
  )
218
 
219
  def integrate_speech_component():
220
- """Integrate speech component with timer-based updates."""
221
  if "voice_transcript" not in st.session_state:
222
  st.session_state.voice_transcript = ""
223
 
224
- # Create the component and get its value
225
- value = create_speech_component()
226
-
227
- # If we got a value from the component, update session state
228
- if value is not None and value != "":
229
- st.session_state.voice_transcript = value
230
- # Debug output
231
- st.write("Updated transcript:", value)
 
 
 
232
 
233
  return st.session_state.voice_transcript
234
-
235
 
236
 
237
 
@@ -1056,24 +1058,20 @@ def main():
1056
  horizontal=True)
1057
 
1058
  if tab_main == "๐ŸŽค Voice Input":
1059
- st.subheader("Voice Recognition")
1060
-
 
1061
  # Get transcript from the speech component
1062
  current_transcript = integrate_speech_component()
1063
 
1064
  # Display the transcript with live updates
1065
  transcript_placeholder = st.empty()
1066
- transcript_placeholder.text_area(
1067
- "Voice Transcript (Live)",
1068
- value=current_transcript,
1069
- height=100
1070
- )
1071
-
1072
- # Add a status indicator
1073
- status_placeholder = st.empty()
1074
- if current_transcript != st.session_state.get('last_transcript', ''):
1075
- status_placeholder.success("๐Ÿ”ด Recording in progress...")
1076
- st.session_state.last_transcript = current_transcript
1077
 
1078
  # Process buttons
1079
  col1, col2, col3 = st.columns(3)
@@ -1098,15 +1096,9 @@ def main():
1098
  with st.spinner("Searching ArXiv..."):
1099
  arxiv_results = perform_ai_lookup(current_transcript)
1100
  st.markdown(arxiv_results)
1101
-
1102
- elif tab_main == "๐Ÿ“ File Editor":
1103
- if hasattr(st.session_state, 'current_file'):
1104
- st.subheader(f"Editing: {st.session_state.current_file}")
1105
- new_content = st.text_area("Content:", st.session_state.file_content, height=300)
1106
- if st.button("Save Changes"):
1107
- with open(st.session_state.current_file, 'w', encoding='utf-8') as file:
1108
- file.write(new_content)
1109
- st.success("File updated successfully!")
1110
 
1111
 
1112
  # Always show file manager in sidebar
 
217
  )
218
 
219
  def integrate_speech_component():
220
+ """Integrate speech component with proper value handling."""
221
  if "voice_transcript" not in st.session_state:
222
  st.session_state.voice_transcript = ""
223
 
224
+ try:
225
+ # Create the component and get its value
226
+ component = create_speech_component()
227
+
228
+ # Update session state if we have valid data
229
+ if isinstance(component, str) and component.strip():
230
+ st.session_state.voice_transcript = component
231
+ st.text(f"Transcript updated: {len(component)} characters")
232
+
233
+ except Exception as e:
234
+ st.error(f"Error in speech component: {str(e)}")
235
 
236
  return st.session_state.voice_transcript
 
237
 
238
 
239
 
 
1058
  horizontal=True)
1059
 
1060
  if tab_main == "๐ŸŽค Voice Input":
1061
+ st.subheader("Voice Recognition")
1062
+
1063
+ try:
1064
  # Get transcript from the speech component
1065
  current_transcript = integrate_speech_component()
1066
 
1067
  # Display the transcript with live updates
1068
  transcript_placeholder = st.empty()
1069
+ if current_transcript:
1070
+ transcript_placeholder.text_area(
1071
+ "Voice Transcript (Live)",
1072
+ value=current_transcript,
1073
+ height=100
1074
+ )
 
 
 
 
 
1075
 
1076
  # Process buttons
1077
  col1, col2, col3 = st.columns(3)
 
1096
  with st.spinner("Searching ArXiv..."):
1097
  arxiv_results = perform_ai_lookup(current_transcript)
1098
  st.markdown(arxiv_results)
1099
+
1100
+ except Exception as e:
1101
+ st.error(f"Error in voice input tab: {str(e)}")
 
 
 
 
 
 
1102
 
1103
 
1104
  # Always show file manager in sidebar