import os import openai import streamlit as st # Get the OpenAI API key from the environment variable openai.api_key = os.getenv("OPENAI_API_KEY") # Raise an error if the API key is missing if not openai.api_key: raise ValueError("⚠️ OpenAI API key is missing! Add it in Hugging Face environment variables.") # Streamlit UI Setup st.set_page_config(page_title="AI Job Interview Coach", layout="centered") st.title("🎤 AI-Powered Job Interview Coach") st.write("💡 Enter your **job description** and **interview question** to get tailored responses and practical tips.") # User Inputs job_description = st.text_area("📌 Job Description", placeholder="e.g. AI Engineer with expertise in NLP and Deep Learning") interview_question = st.text_input("❓ Interview Question", placeholder="e.g. Explain AI in simple terms.") # 🔹 Feature: Model Selection model_choice = st.selectbox("🧠 Choose AI Model", ["gpt-4", "gpt-3.5-turbo"]) # 🔹 Feature: Response Customization temperature = st.slider("🎛️ Creativity (Temperature)", 0.0, 1.0, 0.7, 0.1) max_tokens = st.slider("✍️ Max Response Length", 50, 500, 300, 50) # Function to Generate AI Response def generate_interview_response(job_description, interview_question): messages = [ {"role": "system", "content": "You are an AI-powered job interview coach. Provide structured responses with practical tips."}, {"role": "user", "content": f"Job Description: {job_description}\nInterview Question: {interview_question}\n\nProvide a detailed response with actionable advice."} ] try: response = openai.chat.completions.create( model=model_choice, messages=messages, max_tokens=max_tokens, temperature=temperature ) return response.choices[0].message.content.strip() except Exception as e: return f"⚠️ Error: {str(e)}" # 🔹 Generate AI Response on Button Click if st.button("🚀 Generate Response"): if job_description and interview_question: response = generate_interview_response(job_description, interview_question) st.subheader("💬 AI Response:") st.write(response) # 🔹 Feature: Save Response if st.button("💾 Save Response"): with open("AI_Interview_Response.txt", "w") as file: file.write(response) st.success("Response saved! You can find the file in your working directory.") # 🔹 Feature: Download Response st.download_button("⬇️ Download Response", response, "interview_response.txt", "text/plain") else: st.error("⚠️ Please enter both a **Job Description** and an **Interview Question**.") # 🔹 Feature: General Interview Tips st.subheader("📌 General Interview Tips") st.write(""" ✅ **Research the Company:** Understand its values, products, and culture. ✅ **Practice Common Questions:** Prepare responses for typical interview questions. ✅ **Use the STAR Method:** Structure your answers with **Situation, Task, Action, and Result**. ✅ **Be Confident & Clear:** Speak slowly, maintain eye contact, and express your thoughts clearly. ✅ **Ask Questions:** Show interest by asking insightful questions about the role and company. """)