Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,9 @@ load_dotenv()
|
|
18 |
# Initialize API key status message globally
|
19 |
initial_api_key_status_message = "Checking API Key..."
|
20 |
|
|
|
|
|
|
|
21 |
# Function to read questions from JSON
|
22 |
def read_questions_from_json(file_path):
|
23 |
if not os.path.exists(file_path):
|
@@ -326,6 +329,7 @@ def conduct_interview(questions, language="English", history_limit=5):
|
|
326 |
def main():
|
327 |
QUESTIONS_FILE_PATH = "questions.json"
|
328 |
try:
|
|
|
329 |
questions = read_questions_from_json(QUESTIONS_FILE_PATH)
|
330 |
num_questions = len(questions) # Count the number of questions
|
331 |
print(f"Loaded {num_questions} questions from {QUESTIONS_FILE_PATH}") # Inform user about question count
|
@@ -356,8 +360,7 @@ def main():
|
|
356 |
"I will ask you a series of questions. Please answer honestly and thoughtfully. "
|
357 |
"When you are ready, click **Start Interview** to begin."
|
358 |
)
|
359 |
-
start_btn = gr.Button("Start Interview", variant="primary")
|
360 |
-
|
361 |
chatbot = gr.Chatbot( # Moved up here
|
362 |
label="Interview Chat",
|
363 |
height=650,
|
@@ -376,7 +379,7 @@ def main():
|
|
376 |
audio_output = gr.Audio(label="Response Audio", autoplay=True) # Moved up here
|
377 |
|
378 |
|
379 |
-
|
380 |
|
381 |
|
382 |
with gr.Row():
|
@@ -396,7 +399,7 @@ def main():
|
|
396 |
os.environ["OPENAI_API_KEY"] = api_key # Caution: Modifying os.environ is session-based
|
397 |
global interview_func, initial_message, final_message, questions, initial_api_key_status_message # Declare globals to update them and questions
|
398 |
initial_api_key_status_message = check_api_key() # Update status immediately after key is entered
|
399 |
-
interview_func, initial_message, final_message = conduct_interview(questions) # Re-init interview function
|
400 |
return initial_api_key_status_message # Return status message
|
401 |
|
402 |
update_api_key_button.click(
|
@@ -409,8 +412,8 @@ def main():
|
|
409 |
# with gr.Tab("Generate Questions"):
|
410 |
with gr.Tab("Generate Questions"):
|
411 |
try:
|
412 |
-
# Assuming these are defined in
|
413 |
-
from
|
414 |
load_json_data,
|
415 |
PROFESSIONS_FILE,
|
416 |
TYPES_FILE,
|
@@ -569,6 +572,7 @@ def main():
|
|
569 |
return [{"role": "assistant", "content": error_message}], "", tts_path
|
570 |
|
571 |
try:
|
|
|
572 |
questions = read_questions_from_json(QUESTIONS_FILE_PATH) # Reload questions in case file changed
|
573 |
interview_func, initial_message, final_message = conduct_interview(questions) # Re-init interview func with new questions
|
574 |
except Exception as e:
|
|
|
18 |
# Initialize API key status message globally
|
19 |
initial_api_key_status_message = "Checking API Key..."
|
20 |
|
21 |
+
# Global variable for questions
|
22 |
+
questions = [] # Declare questions as a global variable
|
23 |
+
|
24 |
# Function to read questions from JSON
|
25 |
def read_questions_from_json(file_path):
|
26 |
if not os.path.exists(file_path):
|
|
|
329 |
def main():
|
330 |
QUESTIONS_FILE_PATH = "questions.json"
|
331 |
try:
|
332 |
+
global questions # Use the global questions variable
|
333 |
questions = read_questions_from_json(QUESTIONS_FILE_PATH)
|
334 |
num_questions = len(questions) # Count the number of questions
|
335 |
print(f"Loaded {num_questions} questions from {QUESTIONS_FILE_PATH}") # Inform user about question count
|
|
|
360 |
"I will ask you a series of questions. Please answer honestly and thoughtfully. "
|
361 |
"When you are ready, click **Start Interview** to begin."
|
362 |
)
|
363 |
+
start_btn = gr.Button(" Start Interview", variant="primary")
|
|
|
364 |
chatbot = gr.Chatbot( # Moved up here
|
365 |
label="Interview Chat",
|
366 |
height=650,
|
|
|
379 |
audio_output = gr.Audio(label="Response Audio", autoplay=True) # Moved up here
|
380 |
|
381 |
|
382 |
+
|
383 |
|
384 |
|
385 |
with gr.Row():
|
|
|
399 |
os.environ["OPENAI_API_KEY"] = api_key # Caution: Modifying os.environ is session-based
|
400 |
global interview_func, initial_message, final_message, questions, initial_api_key_status_message # Declare globals to update them and questions
|
401 |
initial_api_key_status_message = check_api_key() # Update status immediately after key is entered
|
402 |
+
interview_func, initial_message, final_message = conduct_interview(questions) # Re-init interview function, now questions is in scope
|
403 |
return initial_api_key_status_message # Return status message
|
404 |
|
405 |
update_api_key_button.click(
|
|
|
412 |
# with gr.Tab("Generate Questions"):
|
413 |
with gr.Tab("Generate Questions"):
|
414 |
try:
|
415 |
+
# Assuming these are defined in backend2.py
|
416 |
+
from backend3 import (
|
417 |
load_json_data,
|
418 |
PROFESSIONS_FILE,
|
419 |
TYPES_FILE,
|
|
|
572 |
return [{"role": "assistant", "content": error_message}], "", tts_path
|
573 |
|
574 |
try:
|
575 |
+
global questions # Ensure we are using the global questions variable
|
576 |
questions = read_questions_from_json(QUESTIONS_FILE_PATH) # Reload questions in case file changed
|
577 |
interview_func, initial_message, final_message = conduct_interview(questions) # Re-init interview func with new questions
|
578 |
except Exception as e:
|