aasherkamal216 commited on
Commit
fc092f1
·
unverified ·
1 Parent(s): c3e215a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -351,13 +351,13 @@ def handle_groq_response(model_params, api_key, question, chat_history, llm_type
351
 
352
  ###---- MAIN FUNCTION FOR ALL MODELS CONVERSATION HANDLING---###
353
  def process_user_input(message_container, trasncribed_text):
354
- prompt = st.chat_input("Type your question", key="question") or speech_file_added
355
 
356
  if not prompt:
357
  return
358
 
359
  if model_type == "groq":
360
- question = trasncribed_text if speech_file_added else prompt
361
 
362
  if question is None:
363
  message_container.error("Couldn't recognize your speech.", icon="❌")
@@ -380,7 +380,7 @@ def process_user_input(message_container, trasncribed_text):
380
  st.error(f"An error occurred: {e}", icon="❌")
381
 
382
  else: # Gemini models
383
- if not speech_file_added:
384
  message_container.chat_message("user", avatar="user.png").markdown(prompt)
385
  content = [{"type": "text", "text": prompt}]
386
  else:
@@ -493,16 +493,18 @@ else:
493
  for key in session_keys:
494
  if key not in st.session_state:
495
  st.session_state[key] = []
496
-
497
  if "transcribed_text" not in st.session_state:
498
  st.session_state.transcribed_text = None
499
 
 
 
 
500
  ######----- Main Interface -----#######
501
  chat_col1, chat_col2 = st.columns([1,4])
502
 
503
  with chat_col1:
504
  ###--- Audio Recording ---###
505
- speech_file_added = False
506
  if model_type == "google":
507
  audio_bytes = audio_recorder("Speak",
508
  pause_threshold=3,
@@ -530,14 +532,14 @@ else:
530
  }]
531
  }
532
  )
533
- speech_file_added = True
534
 
535
  else:
536
 
537
- st.session_state.transcribed_text = speech_to_text(language="en", just_once=True, key="STT", use_container_width=True)
538
 
539
  if st.session_state.transcribed_text:
540
- speech_file_added = True
541
 
542
  ###--- Session state variables ---###
543
  if "pdf_docx_uploaded" not in st.session_state:
 
351
 
352
  ###---- MAIN FUNCTION FOR ALL MODELS CONVERSATION HANDLING---###
353
  def process_user_input(message_container, trasncribed_text):
354
+ prompt = st.chat_input("Type your question", key="question") or st.session_state.speech_file_added
355
 
356
  if not prompt:
357
  return
358
 
359
  if model_type == "groq":
360
+ question = trasncribed_text if st.session_state.speech_file_added else prompt
361
 
362
  if question is None:
363
  message_container.error("Couldn't recognize your speech.", icon="❌")
 
380
  st.error(f"An error occurred: {e}", icon="❌")
381
 
382
  else: # Gemini models
383
+ if not st.session_state.speech_file_added:
384
  message_container.chat_message("user", avatar="user.png").markdown(prompt)
385
  content = [{"type": "text", "text": prompt}]
386
  else:
 
493
  for key in session_keys:
494
  if key not in st.session_state:
495
  st.session_state[key] = []
496
+
497
  if "transcribed_text" not in st.session_state:
498
  st.session_state.transcribed_text = None
499
 
500
+ if "speech_file_added" not in st.session_state:
501
+ st.session_state.speech_file_added = False
502
+
503
  ######----- Main Interface -----#######
504
  chat_col1, chat_col2 = st.columns([1,4])
505
 
506
  with chat_col1:
507
  ###--- Audio Recording ---###
 
508
  if model_type == "google":
509
  audio_bytes = audio_recorder("Speak",
510
  pause_threshold=3,
 
532
  }]
533
  }
534
  )
535
+ st.session_state.speech_file_added = True
536
 
537
  else:
538
 
539
+ st.session_state.transcribed_text = speech_to_text(language="en", just_once=True, use_container_width=True)
540
 
541
  if st.session_state.transcribed_text:
542
+ st.session_state.speech_file_added = True
543
 
544
  ###--- Session state variables ---###
545
  if "pdf_docx_uploaded" not in st.session_state: