import gradio as gr import openai # ========================= # 1) OpenAI API Key # ========================= openai.api_key = "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" # ========================= # 2) Recruiter first lines # ========================= FIRST_LINES = { "Friendly": "I see you took a few years off. That’s interesting — tell me more about what you learned during that time.", "Tough": "A gap that long raises questions. Why should we consider you over someone with recent experience?" } # ========================= # 3) GPT reply for recruiter # ========================= def get_recruiter_reply(user_text, style, history): prompt = f""" You are a recruiter in an interview. Tone = {style} (friendly or tough). Conversation so far: {history} Candidate just said: {user_text} Rules: - Keep replies under 25 words - Ask one probing question at a time - Avoid repeating previous questions Context: mid-career woman re-entering the workforce Return the next recruiter question only. """ response = openai.ChatCompletion.create( model="gpt-4o-mini", messages=[{"role":"user", "content":prompt}] ) return response.choices[0].message.content.strip() # ========================= # 4) GPT feedback after 10 exchanges # ========================= def get_feedback(history): prompt = f""" Based on this 10-turn transcript: {history} Return concise feedback: - Confidence (0-10) - Strengths (2 bullets) - One improvement tip - Example reframe sentence (<=20 words) """ response = openai.ChatCompletion.create( model="gpt-4o-mini", messages=[{"role":"user", "content":prompt}] ) return response.choices[0].message.content.strip() # ========================= # 5) Dummy TTS function (Gradio handles text-to-speech) # ========================= def speak(text): """ No external TTS API needed. Gradio will synthesize audio automatically. """ return text # ========================= # 6) Conversation handler # ========================= def run_boosty(style, user_voice, history="", turn=1): # Step 1: First recruiter line if turn == 1: first_line = FIRST_LINES[style] history += f"Recruiter ({style}): {first_line}\n" audio = speak(first_line) return "", history, audio, turn + 1, "" # Steps 2-10: transcribe user voice using OpenAI Whisper API with open(user_voice.name, "rb") as f: transcription = openai.Audio.transcriptions.create(file=f, model="whisper-1")["text"] history += f"User: {transcription}\n" # After 10 exchanges → feedback if turn > 10: feedback = get_feedback(history) return "", history, None, turn, feedback # Generate next recruiter line reply = get_recruiter_reply(transcription, style, history) history += f"Recruiter: {reply}\n" audio = speak(reply) return "", history, audio, turn + 1, "" # ========================= # 7) Gradio interface # ========================= with gr.Blocks() as demo: style_var = gr.Radio(["Friendly", "Tough"], label="Choose recruiter style") user_voice = gr.Audio(source="microphone", type="file", label="Speak your reply") history = gr.Textbox(label="Transcript", interactive=False) audio_output = gr.Audio(label="Recruiter voice", type="auto", interactive=False) turn_var = gr.State(value=1) feedback_text = gr.Textbox(label="Feedback", interactive=False) submit_btn = gr.Button("Next") submit_btn.click( fn=run_boosty, inputs=[style_var, user_voice, history, turn_var], outputs=[style_var, history, audio_output, turn_var, feedback_text] ) demo.launch()