Spaces:
Sleeping
Sleeping
| 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. | |
| """) | |