husseinelsaadi commited on
Commit
744457a
·
verified ·
1 Parent(s): d0cc78c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -39
app.py CHANGED
@@ -1919,57 +1919,77 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
1919
 
1920
  submit_btn.click(complete_manual, [user_data, name_in, role_in, seniority_in, skills_in], [user_data, missing_section, interview_pre_section, pre_interview_greeting_md])
1921
 
1922
- def start_interview_immediate(data):
1923
- """Start interview immediately, begin TTS generation in background"""
1924
  state = {
1925
- "questions": [], "answers": [], "timings": [], "question_evaluations": [], "answer_evaluations": [],
1926
- "conversation_history": [], "difficulty_adjustment": None, "question_idx": 0, "max_questions": 3,
1927
- "q_start_time": time.time(), "log": []
 
 
 
 
 
 
 
 
1928
  }
1929
-
1930
- # Generate question text first (fast)
1931
  context = ""
1932
  prompt = build_interview_prompt(
1933
- conversation_history=[], user_response="", context=context, job_role=data["job_role"],
1934
- skills=data["skills"], seniority=data["seniority"], difficulty_adjustment=None, voice_label="neutral"
 
 
 
 
 
 
1935
  )
 
 
1936
  first_q = groq_llm.predict(prompt)
1937
- q_eval = {"Score": "N/A", "Reasoning": "Skipped to reduce processing time", "Improvements": []}
1938
-
 
 
 
 
1939
  state["questions"].append(first_q)
1940
  state["question_evaluations"].append(q_eval)
1941
  state["conversation_history"].append({'role': 'Interviewer', 'content': first_q})
1942
- state["log"].append({"type": "question", "question": first_q, "question_eval": q_eval, "timestamp": time.time()})
1943
-
1944
- # Start TTS generation in background
1945
- tts_future_obj = bark_tts_async(first_q)
1946
-
1947
- # Return immediately with loading message
1948
- return (state, tts_future_obj,
1949
- gr.update(visible=False),
1950
- gr.update(visible=True),
1951
- gr.update(visible=True, value="🔄 Generating audio..."),
1952
- gr.update(value=None),
1953
- f"*Question 1:* {first_q}")
1954
-
1955
- def check_tts_ready(state, tts_future_obj):
1956
- """Check if TTS is ready and update audio"""
1957
- if tts_future_obj and tts_future_obj.done():
1958
- try:
1959
- audio_path = tts_future_obj.result()
1960
- return gr.update(value=audio_path), gr.update(visible=False), None
1961
- except Exception as e:
1962
- print(f"TTS Error: {e}")
1963
- return gr.update(value=None), gr.update(value=f"Error generating audio: {e}"), None
1964
- else:
1965
- return gr.update(), gr.update(), tts_future_obj
1966
-
1967
  start_interview_final_btn.click(
1968
- start_interview_immediate,
1969
- [user_data],
1970
- [interview_state, tts_future, interview_pre_section, interview_section, loading_status, question_audio, question_text]
1971
  )
1972
 
 
1973
  def transcribe(audio_path):
1974
  return whisper_stt(audio_path)
1975
 
 
1919
 
1920
  submit_btn.click(complete_manual, [user_data, name_in, role_in, seniority_in, skills_in], [user_data, missing_section, interview_pre_section, pre_interview_greeting_md])
1921
 
1922
+ def start_interview(data):
1923
+ # Initialize interview state
1924
  state = {
1925
+ "questions": [],
1926
+ "answers": [],
1927
+ "timings": [],
1928
+ "question_evaluations": [],
1929
+ "answer_evaluations": [],
1930
+ "conversation_history": [],
1931
+ "difficulty_adjustment": None,
1932
+ "question_idx": 0,
1933
+ "max_questions": 3,
1934
+ "q_start_time": time.time(),
1935
+ "log": []
1936
  }
1937
+
1938
+ # Build prompt for first question
1939
  context = ""
1940
  prompt = build_interview_prompt(
1941
+ conversation_history=[],
1942
+ user_response="",
1943
+ context=context,
1944
+ job_role=data["job_role"],
1945
+ skills=data["skills"],
1946
+ seniority=data["seniority"],
1947
+ difficulty_adjustment=None,
1948
+ voice_label="neutral"
1949
  )
1950
+
1951
+ # Generate first question
1952
  first_q = groq_llm.predict(prompt)
1953
+ q_eval = {
1954
+ "Score": "N/A",
1955
+ "Reasoning": "Skipped to reduce processing time",
1956
+ "Improvements": []
1957
+ }
1958
+
1959
  state["questions"].append(first_q)
1960
  state["question_evaluations"].append(q_eval)
1961
  state["conversation_history"].append({'role': 'Interviewer', 'content': first_q})
1962
+
1963
+ # Generate audio with Bark (wait for it)
1964
+ start = time.perf_counter()
1965
+ audio_future = bark_tts_async(first_q)
1966
+ audio_path = audio_future.result()
1967
+ print("⏱️ Bark TTS took", round(time.perf_counter() - start, 2), "seconds")
1968
+
1969
+ # Log question
1970
+ state["log"].append({
1971
+ "type": "question",
1972
+ "question": first_q,
1973
+ "question_eval": q_eval,
1974
+ "timestamp": time.time()
1975
+ })
1976
+
1977
+ return (
1978
+ state,
1979
+ gr.update(visible=False), # Hide interview_pre_section
1980
+ gr.update(visible=True), # Show interview_section
1981
+ audio_path, # Set audio
1982
+ f"*Question 1:* {first_q}" # Set question text
1983
+ )
1984
+
1985
+ # Hook into Gradio
 
1986
  start_interview_final_btn.click(
1987
+ start_interview,
1988
+ [user_data],
1989
+ [interview_state, interview_pre_section, interview_section, question_audio, question_text]
1990
  )
1991
 
1992
+
1993
  def transcribe(audio_path):
1994
  return whisper_stt(audio_path)
1995