Spaces:
Sleeping
Sleeping
File size: 3,294 Bytes
23be2dd 49c5823 23be2dd 49c5823 a068684 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 23be2dd 49c5823 |
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 |
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.
""")
|