Spaces:
Sleeping
Sleeping
Download app.py from Meenakshi9182/SmartInterview: direct link, hf CLI and curl.
- Browser
- Download file 10.6 kB
-
https://huggingface.co/spaces/Meenakshi9182/SmartInterview/resolve/main/app.py
- Command line
-
hf download hf://spaces/Meenakshi9182/SmartInterview/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Meenakshi9182/SmartInterview/resolve/main/app.py
10.6 kB
| import streamlit as st | |
| import json | |
| from dotenv import load_dotenv | |
| from langchain_core.prompts import ChatPromptTemplate | |
| from langchain_google_genai import ChatGoogleGenerativeAI | |
| from langchain_core.output_parsers import StrOutputParser | |
| # ========================================== | |
| # Load Environment Variables | |
| # ========================================== | |
| load_dotenv() | |
| # ========================================== | |
| # Streamlit Page Config | |
| # ========================================== | |
| st.set_page_config( | |
| page_title="AI Interview Assistant", | |
| page_icon="🎯", | |
| layout="wide" | |
| ) | |
| # ========================================== | |
| # Custom Styling | |
| # ========================================== | |
| page_bg = """ | |
| <style> | |
| /* Main Background */ | |
| [data-testid="stAppViewContainer"] { | |
| background-image: url("https://images.unsplash.com/photo-1522202176988-66273c2fd55f"); | |
| background-size: cover; | |
| background-position: center; | |
| background-repeat: no-repeat; | |
| background-attachment: fixed; | |
| } | |
| /* Transparent Header */ | |
| [data-testid="stHeader"] { | |
| background: rgba(0,0,0,0); | |
| } | |
| /* Sidebar */ | |
| [data-testid="stSidebar"] { | |
| background: rgba(255,255,255,0.08); | |
| } | |
| /* Text Area */ | |
| .stTextArea textarea { | |
| background-color: rgba(0,0,0,0.80); | |
| color: white; | |
| border: 2px solid #6C63FF; | |
| border-radius: 12px; | |
| font-size: 16px; | |
| } | |
| /* Select Box */ | |
| .stSelectbox div[data-baseweb="select"] { | |
| background-color: rgba(255,255,255,0.10); | |
| border-radius: 10px; | |
| } | |
| /* Buttons */ | |
| .stButton button { | |
| background: linear-gradient(90deg, #6C63FF, #8E2DE2); | |
| color: white; | |
| border: none; | |
| border-radius: 12px; | |
| height: 3.2em; | |
| width: 100%; | |
| font-size: 18px; | |
| font-weight: bold; | |
| } | |
| /* Headings */ | |
| h1, h2, h3, h4 { | |
| color: white !important; | |
| } | |
| /* Paragraph */ | |
| p, label { | |
| color: white !important; | |
| font-size: 18px; | |
| } | |
| /* Success Box */ | |
| .stAlert { | |
| border-radius: 12px; | |
| } | |
| /* Metric Cards */ | |
| [data-testid="metric-container"] { | |
| background-color: rgba(255,255,255,0.12); | |
| border-radius: 15px; | |
| padding: 15px; | |
| border: 1px solid rgba(255,255,255,0.2); | |
| } | |
| /* JSON Output */ | |
| .stJson { | |
| background-color: rgba(255,255,255,0.10); | |
| border-radius: 10px; | |
| padding: 10px; | |
| } | |
| </style> | |
| """ | |
| st.markdown(page_bg, unsafe_allow_html=True) | |
| # ========================================== | |
| # Title Section | |
| # ========================================== | |
| st.title("Smart Interview Preparation Assistant") | |
| st.subheader("AI-Powered Interview Evaluation System") | |
| st.write( | |
| "Generate interview questions and receive professional AI feedback instantly." | |
| ) | |
| # ========================================== | |
| # Interview Type | |
| # ========================================== | |
| role = st.selectbox( | |
| "Select Interview Type", | |
| ["HR", "Technical", "General"] | |
| ) | |
| # ========================================== | |
| # Gemini Model | |
| # ========================================== | |
| model = ChatGoogleGenerativeAI( | |
| model="gemini-2.5-flash", | |
| temperature=0.3 | |
| ) | |
| parser = StrOutputParser() | |
| # ========================================== | |
| # Question Prompt | |
| # ========================================== | |
| question_prompt = ChatPromptTemplate.from_messages([ | |
| ( | |
| "system", | |
| """ | |
| You are an expert interviewer. | |
| Generate SHORT interview questions only. | |
| Rules: | |
| - Keep question under 20 words | |
| - Beginner friendly | |
| - No paragraph questions | |
| """ | |
| ), | |
| ( | |
| "human", | |
| "Generate one {role} interview question." | |
| ) | |
| ]) | |
| question_chain = question_prompt | model | parser | |
| # ========================================== | |
| # Generate Question Button | |
| # ========================================== | |
| if st.button("Generate Interview Question"): | |
| try: | |
| with st.spinner("Generating question..."): | |
| response = question_chain.invoke({ | |
| "role": role | |
| }) | |
| st.session_state.question = response | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| # ========================================== | |
| # Show Question | |
| # ========================================== | |
| if "question" in st.session_state: | |
| st.subheader("Interview Question") | |
| st.success(st.session_state.question) | |
| # ========================================== | |
| # User Answer | |
| # ========================================== | |
| answer = st.text_area( | |
| "✍️ Write Your Answer", | |
| height=200, | |
| placeholder="Example: OOP stands for Object-Oriented Programming..." | |
| ) | |
| # ========================================== | |
| # Evaluation Prompt | |
| # ========================================== | |
| template = """ | |
| You are an expert HR interviewer. | |
| Evaluate the candidate answer professionally. | |
| Return ONLY valid JSON. | |
| Expected JSON format: | |
| {{ | |
| "question": "interview question", | |
| "candidate_answer": "user answer", | |
| "evaluation": {{ | |
| "strengths": [ | |
| "strength1", | |
| "strength2" | |
| ], | |
| "weaknesses": [ | |
| "weakness1", | |
| "weakness2" | |
| ] | |
| }}, | |
| "scores": {{ | |
| "technical_knowledge": "8/10", | |
| "communication": "7/10", | |
| "confidence": "8/10", | |
| "overall": "8/10" | |
| }}, | |
| "final_feedback": "professional feedback" | |
| }} | |
| """ | |
| prompt = ChatPromptTemplate.from_messages([ | |
| ("system", template), | |
| ("human", """ | |
| Question: | |
| {question} | |
| Answer: | |
| {answer} | |
| """) | |
| ]) | |
| evaluation_chain = prompt | model | parser | |
| # ========================================== | |
| # Evaluate Answer | |
| # ========================================== | |
| if st.button("Evaluate Answer"): | |
| if answer.strip(): | |
| with st.spinner("Evaluating answer..."): | |
| try: | |
| response = evaluation_chain.invoke({ | |
| "question": st.session_state.question, | |
| "answer": answer | |
| }) | |
| cleaned_response = ( | |
| response | |
| .replace("```json", "") | |
| .replace("```", "") | |
| .strip() | |
| ) | |
| data = json.loads(cleaned_response) | |
| # ========================================== | |
| # Display Results | |
| # ========================================== | |
| st.subheader("Question") | |
| st.write(data.get("question", "N/A")) | |
| st.subheader("Candidate Answer") | |
| st.write(data.get("candidate_answer", "N/A")) | |
| # ========================================== | |
| # Strengths | |
| # ========================================== | |
| st.subheader("Strengths") | |
| strengths = data.get( | |
| "evaluation", {} | |
| ).get("strengths", []) | |
| for item in strengths: | |
| st.write(f"• {item}") | |
| # ========================================== | |
| # Weaknesses | |
| # ========================================== | |
| st.subheader("Weaknesses") | |
| weaknesses = data.get( | |
| "evaluation", {} | |
| ).get("weaknesses", []) | |
| for item in weaknesses: | |
| st.write(f"• {item}") | |
| # ========================================== | |
| # Scores | |
| # ========================================== | |
| st.subheader("Performance Scores") | |
| scores = data.get("scores", {}) | |
| col1, col2 = st.columns(2) | |
| with col1: | |
| st.metric( | |
| "Technical Knowledge", | |
| scores.get( | |
| "technical_knowledge", | |
| "N/A" | |
| ) | |
| ) | |
| st.metric( | |
| "Communication", | |
| scores.get( | |
| "communication", | |
| "N/A" | |
| ) | |
| ) | |
| with col2: | |
| st.metric( | |
| "Confidence", | |
| scores.get( | |
| "confidence", | |
| "N/A" | |
| ) | |
| ) | |
| st.metric( | |
| "Overall", | |
| scores.get( | |
| "overall", | |
| "N/A" | |
| ) | |
| ) | |
| # ========================================== | |
| # Final Feedback | |
| # ========================================== | |
| st.subheader("Final Feedback") | |
| st.write( | |
| data.get( | |
| "final_feedback", | |
| "N/A" | |
| ) | |
| ) | |
| # ========================================== | |
| # Full JSON Output | |
| # ========================================== | |
| st.subheader("Full JSON Output") | |
| st.json(data) | |
| except json.JSONDecodeError: | |
| st.error("Invalid JSON received from Gemini.") | |
| st.code(response) | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| else: | |
| st.warning("Please enter your answer.") | |
| # ========================================== | |
| # Footer | |
| # ========================================== | |
| st.markdown("---") | |
| st.write("Built with Streamlit + Gemini AI + LangChain") |