File size: 3,907 Bytes
c6bb23b
 
 
 
 
 
11c2e98
c6bb23b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c2d35b7
29003e5
c2d35b7
c6bb23b
29003e5
c2d35b7
c6bb23b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
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()