CoolFace
Apppublic

batoolaa1/AceBot_AI_Interview_Coach

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
app.py101 linesDownload Raw Back to root
1import gradio as gr2from groq import Groq3 4# Groq API Key5api_key = "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"6client = Groq(api_key=api_key)7 8# Conversation history9conversation_history = []10 11# Generate interview responses using Groq's Llama 3 model12def interview_coach(user_input, language):13    global conversation_history14 15    system_message = "You are a professional AI coach that provides mock interview questions and advice."16    if language == "French":17        system_message += " Please respond in French."18    else:19        system_message += " Please respond in English."20    21    if len(conversation_history) == 0 or conversation_history[0]['role'] != 'system':22        conversation_history.insert(0, {"role": "system", "content": system_message})23    else:24        conversation_history[0]["content"] = system_message25 26    conversation_history.append({"role": "user", "content": user_input})27 28    try:29        response = client.chat.completions.create(30            model="llama3-70b-8192",  31            messages=[{"role": msg['role'], "content": msg['content']} for msg in conversation_history],32            temperature=1,33            max_tokens=1024,34            top_p=1,35            stream=True,36            stop=None,37        )38        39        response_content = ""40        for chunk in response:41            response_content += chunk.choices[0].delta.content or ""42 43        conversation_history.append({"role": "assistant", "content": response_content})44        return conversation_history45    46    except Exception as e:47        return f"Error: {str(e)}"48 49# Function to clear the input box50def clear_input(_):51    return ""  # Returning an empty string clears the input box52 53# Gradio UI54with gr.Blocks(theme=gr.themes.Base()) as acebot_ui:55    with gr.Sidebar():56        font_size_slider = gr.Slider(minimum=10, maximum=30, value=16, label="Font Size")57        refresh_button = gr.Button("๐Ÿ”„ Refresh Chat")58    59    with gr.Tabs():60        with gr.TabItem("๐Ÿ’ฌ Chat with AceBot"):61            gr.HTML("""62            <h1>๐Ÿ‘” AceBot</h1>63            <p>Ask me anything about interview questions, how to answer them, and strategies to impress employers!</p>64            """)65            66            with gr.Column():67                with gr.Row():68                    sample1 = gr.Button("๐Ÿง  What are common behavioral interview questions?")69                    sample2 = gr.Button("๐Ÿ’ฌ How do I answer 'Tell me about yourself'?")70                    sample3 = gr.Button("๐Ÿ˜จ What are the best strategies to calm interview nerves?")71            72            chatbot = gr.Chatbot(label="AceBot Interview Chat", type="messages", height=500)73            74            with gr.Row():75                with gr.Column(scale=9):76                    user_input = gr.Textbox(label="Your Interview Question", placeholder="Ask about interview strategies...", lines=1, max_lines=1)77                with gr.Column(scale=1):78                    send_button = gr.Button("๐Ÿš€ Get Answer")79            80            language_selector = gr.Radio(["English", "French"], label="Choose Language", value="English")81            82            def on_submit_or_button_click(user_input, language_selector):83                return interview_coach(user_input, language_selector)84            85            user_input.submit(fn=on_submit_or_button_click, inputs=[user_input, language_selector], outputs=chatbot).then(86                fn=clear_input, inputs=[user_input], outputs=[user_input]87            )88            89            send_button.click(fn=on_submit_or_button_click, inputs=[user_input, language_selector], outputs=chatbot).then(90                fn=clear_input, inputs=[user_input], outputs=[user_input]91            )92            93            sample1.click(fn=lambda: "๐Ÿง  What are common behavioral interview questions?", inputs=[], outputs=user_input)94            sample2.click(fn=lambda: "๐Ÿ’ฌ How do I answer 'Tell me about yourself'?", inputs=[], outputs=user_input)95            sample3.click(fn=lambda: "๐Ÿ˜จ What are the best strategies to calm interview nerves?", inputs=[], outputs=user_input)96            97            refresh_button.click(fn=lambda: None, inputs=[], outputs=chatbot)98 99# Launch the app100acebot_ui.launch()101