import streamlit as st import os from groq import Groq from gtts import gTTS from langchain_community.document_loaders import PyPDFLoader import tempfile import base64 # --- CONFIGURATION --- st.set_page_config(page_title="Zara: AI Interviewer", page_icon="👩💼", layout="wide") # API Key Check if "GROQ_API_KEY" in st.secrets: api_key = st.secrets["GROQ_API_KEY"] else: st.error("GROQ_API_KEY not found in secrets!") st.stop() client = Groq(api_key=api_key) # --- AVATAR URLLERİ (Burayı değiştirebilirsin) --- # "Idle": Dinlerken duran (hafif hareketli) avatar AVATAR_IDLE = "https://media1.giphy.com/media/v1.Y2lkPTc5MGI3NjExcDd5Y3h6a2txY3Z4bnZtY3Z4bnZtY3Z4bnZtY3Z4bnZtY3Z4bnZtJmVwPXYxX2ludGVybmFsX2dpZl9ieV9pZCZjdD1n/l3V0yA9zHe5m29sxW/giphy.gif" # "Talking": Konuşurken ağzı oynayan avatar AVATAR_TALKING = "https://media3.giphy.com/media/v1.Y2lkPTc5MGI3NjExYnZ5Y3h6a2txY3Z4bnZtY3Z4bnZtY3Z4bnZtY3Z4bnZtY3Z4bnZtJmVwPXYxX2ludGVybmFsX2dpZl9ieV9pZCZjdD1n/3o7TKs69j4h9vK6qTm/giphy.gif" # --- CUSTOM CSS (Görüntülü Arama Havası İçin) --- st.markdown(""" """, unsafe_allow_html=True) # --- FUNCTIONS --- def get_response_from_llm(chat_history, resume_text): system_prompt = f""" You are Zara, a professional AI Technical Recruiter. INTERVIEW STYLE: Professional, encouraging, but rigorous. TASK: 1. Analyze the candidate's RESUME. 2. Conduct a voice interview. Ask ONE question at a time. 3. Keep responses concise (under 3 sentences) so the conversation flows naturally. OUTPUT FORMAT: [Feedback/Question] ||| [Hint/Strategy] RESUME CONTEXT: {resume_text} """ messages = [{"role": "system", "content": system_prompt}] + chat_history try: completion = client.chat.completions.create( model="llama-3.3-70b-versatile", messages=messages, temperature=0.6, max_tokens=250, ) return completion.choices[0].message.content except Exception as e: return f"Error: {e} ||| No hint." def text_to_speech(text): try: tts = gTTS(text=text, lang='en') filename = "response.mp3" tts.save(filename) return filename except: return None def extract_text_from_pdf(uploaded_file): with tempfile.NamedTemporaryFile(delete=False) as tmp_file: tmp_file.write(uploaded_file.getvalue()) tmp_path = tmp_file.name loader = PyPDFLoader(tmp_path) pages = loader.load() return "".join([p.page_content for p in pages]) # --- UI LAYOUT --- # Header col1, col2 = st.columns([1, 4]) with col1: st.title("🎙️ Zara") with col2: st.markdown("*AI Interview Coach*") # Session State if "chat_history" not in st.session_state: st.session_state.chat_history = [] if "resume_text" not in st.session_state: st.session_state.resume_text = "" if "current_hint" not in st.session_state: st.session_state.current_hint = "Upload your CV to start!" if "avatar_state" not in st.session_state: st.session_state.avatar_state = "idle" # idle or talking # Sidebar with st.sidebar: st.header("⚙️ Setup") uploaded_file = st.file_uploader("Upload CV (PDF)", type="pdf") if st.button("Reset Interview"): st.session_state.clear() st.rerun() # --- AVATAR DISPLAY AREA (CENTER STAGE) --- avatar_placeholder = st.empty() def render_avatar(state): image_url = AVATAR_TALKING if state == "talking" else AVATAR_IDLE avatar_placeholder.markdown(f"""