pk75 commited on
Commit
7f1907b
·
verified ·
1 Parent(s): 5acc094

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -15
app.py CHANGED
@@ -17,14 +17,12 @@ def start_interview(interview_type, doc_file, name, num_questions):
17
  chatbot: gr.update(value=[[None, "Please select an interview type and upload a document to begin."]]),
18
  audio_in: gr.update(interactive=False)
19
  }
20
-
21
  doc_text = extract_text_from_document(doc_file.name)
22
  if "Error" in doc_text or "Unsupported" in doc_text:
23
  return {
24
  chatbot: gr.update(value=[[None, f"Error: {doc_text}"]]),
25
  audio_in: gr.update(interactive=False)
26
  }
27
-
28
  initial_state = {
29
  "interview_type": interview_type,
30
  "doc_text": doc_text,
@@ -34,15 +32,11 @@ def start_interview(interview_type, doc_file, name, num_questions):
34
  "interview_log": [],
35
  "start_time": time.time()
36
  }
37
-
38
  first_question = generate_question(interview_type, doc_text)
39
  initial_state["current_question_text"] = first_question
40
-
41
  greeting = f"Hello {initial_state['name']}. We'll go through {int(num_questions)} questions today. Here is your first question:"
42
-
43
  tts_prompt = f"{greeting} {first_question}"
44
  ai_voice_path = text_to_speech_file(tts_prompt)
45
-
46
  return {
47
  state: initial_state,
48
  chatbot: gr.update(value=[[None, f"{greeting}\n\n{first_question}"]]),
@@ -62,14 +56,11 @@ def handle_interview_turn(user_audio, chatbot_history, current_state):
62
  "answer": user_answer_text,
63
  "evaluation": evaluation_text
64
  })
65
-
66
  if current_state["current_question_num"] >= current_state["question_count"]:
67
  end_message = "This concludes the interview. Generating your final report now."
68
  chatbot_history.append([None, end_message])
69
-
70
  pdf_path = generate_pdf_file(current_state)
71
  ai_voice_path = text_to_speech_file(end_message)
72
-
73
  yield {
74
  chatbot: chatbot_history,
75
  audio_out: gr.update(value=ai_voice_path, autoplay=True),
@@ -79,13 +70,10 @@ def handle_interview_turn(user_audio, chatbot_history, current_state):
79
  current_state["current_question_num"] += 1
80
  next_question = generate_question(current_state["interview_type"], current_state["doc_text"])
81
  current_state["current_question_text"] = next_question
82
-
83
  q_num = current_state["current_question_num"]
84
  transition_message = f"Thank you. Here is question {q_num}:\n\n{next_question}"
85
  chatbot_history.append([None, transition_message])
86
-
87
  ai_voice_path = text_to_speech_file(transition_message)
88
-
89
  yield {
90
  state: current_state,
91
  chatbot: chatbot_history,
@@ -94,7 +82,6 @@ def handle_interview_turn(user_audio, chatbot_history, current_state):
94
  }
95
 
96
  def generate_pdf_file(state):
97
- # This function now correctly creates the dictionary for the report generator
98
  total_duration_minutes = (time.time() - state.get("start_time", time.time())) / 60
99
  final_data = {
100
  "name": state.get("name", "N/A"),
@@ -109,14 +96,20 @@ def generate_pdf_file(state):
109
 
110
  with gr.Blocks(theme=gr.themes.Default()) as app:
111
  state = gr.State({})
112
- gr.Markdown("# AI Interview Coach for Super Kalam")
113
  with gr.Row():
114
  with gr.Column(scale=1):
115
  gr.Markdown("### Setup")
116
  user_name = gr.Textbox(label="Your Name")
117
  interview_type_dd = gr.Dropdown(config.INTERVIEW_TYPES, label="Interview Type")
118
  num_questions_slider = gr.Slider(minimum=2, maximum=10, value=5, step=1, label="Number of Questions")
119
- doc_uploader = gr.File(label="Upload Resume/CV")
 
 
 
 
 
 
120
  start_btn = gr.Button("Start Interview", variant="primary")
121
 
122
  with gr.Column(scale=2):
 
17
  chatbot: gr.update(value=[[None, "Please select an interview type and upload a document to begin."]]),
18
  audio_in: gr.update(interactive=False)
19
  }
 
20
  doc_text = extract_text_from_document(doc_file.name)
21
  if "Error" in doc_text or "Unsupported" in doc_text:
22
  return {
23
  chatbot: gr.update(value=[[None, f"Error: {doc_text}"]]),
24
  audio_in: gr.update(interactive=False)
25
  }
 
26
  initial_state = {
27
  "interview_type": interview_type,
28
  "doc_text": doc_text,
 
32
  "interview_log": [],
33
  "start_time": time.time()
34
  }
 
35
  first_question = generate_question(interview_type, doc_text)
36
  initial_state["current_question_text"] = first_question
 
37
  greeting = f"Hello {initial_state['name']}. We'll go through {int(num_questions)} questions today. Here is your first question:"
 
38
  tts_prompt = f"{greeting} {first_question}"
39
  ai_voice_path = text_to_speech_file(tts_prompt)
 
40
  return {
41
  state: initial_state,
42
  chatbot: gr.update(value=[[None, f"{greeting}\n\n{first_question}"]]),
 
56
  "answer": user_answer_text,
57
  "evaluation": evaluation_text
58
  })
 
59
  if current_state["current_question_num"] >= current_state["question_count"]:
60
  end_message = "This concludes the interview. Generating your final report now."
61
  chatbot_history.append([None, end_message])
 
62
  pdf_path = generate_pdf_file(current_state)
63
  ai_voice_path = text_to_speech_file(end_message)
 
64
  yield {
65
  chatbot: chatbot_history,
66
  audio_out: gr.update(value=ai_voice_path, autoplay=True),
 
70
  current_state["current_question_num"] += 1
71
  next_question = generate_question(current_state["interview_type"], current_state["doc_text"])
72
  current_state["current_question_text"] = next_question
 
73
  q_num = current_state["current_question_num"]
74
  transition_message = f"Thank you. Here is question {q_num}:\n\n{next_question}"
75
  chatbot_history.append([None, transition_message])
 
76
  ai_voice_path = text_to_speech_file(transition_message)
 
77
  yield {
78
  state: current_state,
79
  chatbot: chatbot_history,
 
82
  }
83
 
84
  def generate_pdf_file(state):
 
85
  total_duration_minutes = (time.time() - state.get("start_time", time.time())) / 60
86
  final_data = {
87
  "name": state.get("name", "N/A"),
 
96
 
97
  with gr.Blocks(theme=gr.themes.Default()) as app:
98
  state = gr.State({})
99
+ gr.Markdown("# 🤖 AI Interview Coach")
100
  with gr.Row():
101
  with gr.Column(scale=1):
102
  gr.Markdown("### Setup")
103
  user_name = gr.Textbox(label="Your Name")
104
  interview_type_dd = gr.Dropdown(config.INTERVIEW_TYPES, label="Interview Type")
105
  num_questions_slider = gr.Slider(minimum=2, maximum=10, value=5, step=1, label="Number of Questions")
106
+
107
+ # --- THIS IS THE UPDATED COMPONENT ---
108
+ doc_uploader = gr.File(
109
+ label="Upload Resume/CV (.pdf, .docx)",
110
+ file_types=['.pdf', '.docx']
111
+ )
112
+
113
  start_btn = gr.Button("Start Interview", variant="primary")
114
 
115
  with gr.Column(scale=2):