Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -350,34 +350,9 @@ def main():
|
|
| 350 |
# Build Gradio interface
|
| 351 |
with gr.Blocks(css=css) as demo:
|
| 352 |
gr.Markdown(
|
| 353 |
-
"<h1 style='text-align:center;'>π AI HR Interview Assistant</h1>"
|
| 354 |
-
)
|
| 355 |
-
gr.Markdown(
|
| 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 |
|
| 360 |
-
start_btn = gr.Button("Start Interview", variant="primary")
|
| 361 |
-
chatbot = gr.Chatbot(
|
| 362 |
-
label="Interview Chat",
|
| 363 |
-
height=650,
|
| 364 |
-
type='messages' # must return a list of dicts: {"role":..., "content":...}
|
| 365 |
-
)
|
| 366 |
-
audio_input = gr.Audio(
|
| 367 |
-
sources=["microphone"],
|
| 368 |
-
type="filepath",
|
| 369 |
-
label="Record Your Answer"
|
| 370 |
-
)
|
| 371 |
-
user_input = gr.Textbox(
|
| 372 |
-
label="Your Response",
|
| 373 |
-
placeholder="Type your answer here or use the microphone...",
|
| 374 |
-
lines=1,
|
| 375 |
-
)
|
| 376 |
-
audio_output = gr.Audio(label="Response Audio", autoplay=True)
|
| 377 |
-
|
| 378 |
-
with gr.Row():
|
| 379 |
-
submit_btn = gr.Button("Submit", variant="primary")
|
| 380 |
-
clear_btn = gr.Button("Clear Chat")
|
| 381 |
|
| 382 |
# Admin Panel Tab
|
| 383 |
with gr.Tab("Admin Panel", id="admin_tab"):
|
|
@@ -390,8 +365,15 @@ def main():
|
|
| 390 |
|
| 391 |
def update_api_key(api_key):
|
| 392 |
os.environ["OPENAI_API_KEY"] = api_key # Caution: Modifying os.environ is session-based
|
| 393 |
-
global interview_func, initial_message, final_message,
|
| 394 |
initial_api_key_status_message = check_api_key() # Update status immediately after key is entered
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 395 |
interview_func, initial_message, final_message = conduct_interview(questions) # Re-init interview function
|
| 396 |
return initial_api_key_status_message # Return status message
|
| 397 |
|
|
@@ -406,7 +388,7 @@ def main():
|
|
| 406 |
with gr.Tab("Generate Questions"):
|
| 407 |
try:
|
| 408 |
# Assuming these are defined in backend2.py
|
| 409 |
-
from
|
| 410 |
load_json_data,
|
| 411 |
PROFESSIONS_FILE,
|
| 412 |
TYPES_FILE,
|
|
@@ -637,8 +619,7 @@ def main():
|
|
| 637 |
inputs=[user_input, audio_input, chatbot],
|
| 638 |
outputs=[chatbot, user_input, audio_output]
|
| 639 |
)
|
| 640 |
-
|
| 641 |
-
# 4) Pressing Enter in the textbox
|
| 642 |
user_input.submit(
|
| 643 |
on_enter_submit,
|
| 644 |
inputs=[chatbot, user_input],
|
|
@@ -652,6 +633,7 @@ def main():
|
|
| 652 |
outputs=[chatbot, user_input, audio_output]
|
| 653 |
)
|
| 654 |
|
|
|
|
| 655 |
# Launch Gradio (remove `share=True` if it keeps failing)
|
| 656 |
demo.launch(
|
| 657 |
server_name="0.0.0.0",
|
|
|
|
| 350 |
# Build Gradio interface
|
| 351 |
with gr.Blocks(css=css) as demo:
|
| 352 |
gr.Markdown(
|
| 353 |
+
"<h1 style='text-align:center;'>π AI HR Interview Assistant - Admin Panel</h1>"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
)
|
| 355 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
# Admin Panel Tab
|
| 358 |
with gr.Tab("Admin Panel", id="admin_tab"):
|
|
|
|
| 365 |
|
| 366 |
def update_api_key(api_key):
|
| 367 |
os.environ["OPENAI_API_KEY"] = api_key # Caution: Modifying os.environ is session-based
|
| 368 |
+
global interview_func, initial_message, final_message, initial_api_key_status_message # Declare globals to update them
|
| 369 |
initial_api_key_status_message = check_api_key() # Update status immediately after key is entered
|
| 370 |
+
QUESTIONS_FILE_PATH = "questions.json" # Define QUESTIONS_FILE_PATH here
|
| 371 |
+
try:
|
| 372 |
+
questions = read_questions_from_json(QUESTIONS_FILE_PATH) # reload questions here to fix NameError: name 'questions' is not defined
|
| 373 |
+
except Exception as e:
|
| 374 |
+
print(f"Error reloading questions in update_api_key: {e}")
|
| 375 |
+
return f"β Error reloading questions: {e}"
|
| 376 |
+
|
| 377 |
interview_func, initial_message, final_message = conduct_interview(questions) # Re-init interview function
|
| 378 |
return initial_api_key_status_message # Return status message
|
| 379 |
|
|
|
|
| 388 |
with gr.Tab("Generate Questions"):
|
| 389 |
try:
|
| 390 |
# Assuming these are defined in backend2.py
|
| 391 |
+
from backend2 import (
|
| 392 |
load_json_data,
|
| 393 |
PROFESSIONS_FILE,
|
| 394 |
TYPES_FILE,
|
|
|
|
| 619 |
inputs=[user_input, audio_input, chatbot],
|
| 620 |
outputs=[chatbot, user_input, audio_output]
|
| 621 |
)
|
| 622 |
+
# 4) User input textbox submits (Enter key)
|
|
|
|
| 623 |
user_input.submit(
|
| 624 |
on_enter_submit,
|
| 625 |
inputs=[chatbot, user_input],
|
|
|
|
| 633 |
outputs=[chatbot, user_input, audio_output]
|
| 634 |
)
|
| 635 |
|
| 636 |
+
|
| 637 |
# Launch Gradio (remove `share=True` if it keeps failing)
|
| 638 |
demo.launch(
|
| 639 |
server_name="0.0.0.0",
|