File size: 2,828 Bytes
3320d93
35691fd
3320d93
37fb8e6
35691fd
a1e618e
888c9ce
37fb8e6
888c9ce
a1e618e
888c9ce
a1e618e
 
 
 
2e48300
888c9ce
512a608
2e48300
 
 
 
512a608
 
 
 
 
2e48300
 
 
37fb8e6
2e48300
 
 
 
35691fd
888c9ce
a1e618e
888c9ce
a1e618e
37fb8e6
a1e618e
35691fd
888c9ce
8a4df17
 
 
 
888c9ce
 
 
8a4df17
a1e618e
888c9ce
8a4df17
 
 
a9cdc03
a1e618e
35691fd
 
37fb8e6
35691fd
888c9ce
a1e618e
888c9ce
37fb8e6
a1e618e
2e48300
37fb8e6
 
 
 
 
 
901ff66
888c9ce
35691fd
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
import gradio as gr
from huggingface_hub import InferenceClient

client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")

def set_type(choice, user_profile):
    user_profile["interview_type"] = choice.lower()
    return f"Great! What’s your background and what field/role are you aiming for?", user_profile

def save_background(info, user_profile):
    user_profile["field"] = info
    return "Awesome! Type 'start' below to begin your interview.", user_profile

def respond(message, history, user_profile):
    if not user_profile["interview_type"] or not user_profile["field"]:
        return "Please finish steps 1 and 2 before starting the interview."

    messages = [
        {
            "role": "system",
            "content": f"You are a professional interviewer conducting a {user_profile['interview_type']} interview for a candidate in the {user_profile['field']} field."
        }
    ]
    if history:
        messages.extend(history)
    messages.append({"role": "user", "content": message})

    response = client.chat_completion(
        messages,
        max_tokens=150,
        stream=False
    )

    return response.choices[0].message.content


with gr.Blocks() as demo:
    user_profile = gr.State({"interview_type": "", "field": ""})

    gr.Markdown("# 🎀 Welcome to Intervu")

    # Step 1
    gr.Markdown("### Step 1: Choose Interview Type")
    with gr.Row():
        behavioral_val = gr.Textbox(value="Behavioral", visible=False)
        technical_val = gr.Textbox(value="Technical", visible=False)
        college_val = gr.Textbox(value="College", visible=False)

        btn1 = gr.Button("Behavioral")
        btn2 = gr.Button("Technical")
        btn3 = gr.Button("College / Scholarship")

    type_out = gr.Textbox(label="Bot", interactive=False)

    btn1.click(set_type, inputs=[behavioral_val, user_profile], outputs=[type_out, user_profile])
    btn2.click(set_type, inputs=[technical_val, user_profile], outputs=[type_out, user_profile])
    btn3.click(set_type, inputs=[college_val, user_profile], outputs=[type_out, user_profile])

    # Step 2
    gr.Markdown("### Step 2: Enter Your Background")
    background = gr.Textbox(label="Your background and field/goal")
    background_btn = gr.Button("Submit Background")
    background_out = gr.Textbox(label="Bot", interactive=False)

    background_btn.click(save_background, inputs=[background, user_profile], outputs=[background_out, user_profile])

    # Step 3
    gr.Markdown("### Step 3: Start Interview")
    chatbot = gr.ChatInterface(
        fn=lambda msg, hist: respond(msg, hist, user_profile.value),
        title="Intervu - AI Interview Practice",
        chatbot=gr.Chatbot(label="Interview Bot"),
        input_textbox=gr.Textbox(placeholder="Type your answer here..."),
        type="messages"
    )

demo.launch()