Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,139 +1,122 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
-
import re
|
| 4 |
-
|
| 5 |
-
def generate_question(role, topic, difficulty_level):
|
| 6 |
-
prompt = f"Generate an interview question for the role of {role} on the topic of {topic} with difficulty level {difficulty_level}."
|
| 7 |
-
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 8 |
-
response = llm.invoke(prompt)
|
| 9 |
-
response = response.content
|
| 10 |
-
|
| 11 |
-
return response
|
| 12 |
-
|
| 13 |
-
def evaluate_answer(question, user_answer):
|
| 14 |
-
prompt = f"Question: {question}\nUser's Answer: {user_answer}\nEvaluate the answer and provide feedback. Also, provide the best possible answer."
|
| 15 |
-
llm = ChatGoogleGenerativeAI(model="gemini-pro", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 16 |
-
response = llm.invoke(prompt)
|
| 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 |
-
if
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
"
|
| 78 |
-
"
|
| 79 |
-
"
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
if st.session_state['
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
if st.button("Submit Answer"):
|
| 124 |
-
if answer:
|
| 125 |
-
st.session_state['answers'].append(answer)
|
| 126 |
-
score, feedback = evaluate_answer(st.session_state['questions'][current_question], answer)
|
| 127 |
-
st.session_state['scores'].append(score)
|
| 128 |
-
st.session_state['feedback'].append(feedback)
|
| 129 |
-
st.session_state['question_answered'] = True
|
| 130 |
-
st.write(f"Score: {score}")
|
| 131 |
-
st.write(f"Feedback: {feedback}")
|
| 132 |
-
|
| 133 |
-
if st.session_state['question_answered']:
|
| 134 |
-
if st.button("Next Question"):
|
| 135 |
-
st.session_state['current_question'] += 1
|
| 136 |
-
st.session_state['question_answered'] = False
|
| 137 |
-
else:
|
| 138 |
-
st.write("Interview Complete! Generating Report...")
|
| 139 |
-
generate_report()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
def generate_question(role, topic, difficulty_level):
|
| 6 |
+
prompt = f"Generate an interview question for the role of {role} on the topic of {topic} with difficulty level {difficulty_level}."
|
| 7 |
+
llm = ChatGoogleGenerativeAI(model="gemini-2.5-pro-preview-03-25", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 8 |
+
response = llm.invoke(prompt)
|
| 9 |
+
response = response.content
|
| 10 |
+
|
| 11 |
+
return response
|
| 12 |
+
|
| 13 |
+
def evaluate_answer(question, user_answer):
|
| 14 |
+
prompt = f"Question: {question}\nUser's Answer: {user_answer}\nEvaluate the answer, give a score out of 100, and provide feedback. Also, provide the best possible answer."
|
| 15 |
+
llm = ChatGoogleGenerativeAI(model="gemini-2.5-pro-preview-03-25", google_api_key=st.secrets["GOOGLE_API_KEY"])
|
| 16 |
+
response = llm.invoke(prompt)
|
| 17 |
+
|
| 18 |
+
evaluation = response.content
|
| 19 |
+
# Extract score and feedback from the evaluation
|
| 20 |
+
# Extract score using regular expressions
|
| 21 |
+
score_match = re.search(r'(\d+)/100', evaluation)
|
| 22 |
+
score = int(score_match.group(1)) if score_match else 0
|
| 23 |
+
|
| 24 |
+
# Extract feedback
|
| 25 |
+
feedback = evaluation.split('\n', 1)[1] if '\n' in evaluation else evaluation
|
| 26 |
+
return score, feedback
|
| 27 |
+
|
| 28 |
+
def generate_report():
|
| 29 |
+
st.write("### Interview Report")
|
| 30 |
+
for i in range(st.session_state['total_questions']):
|
| 31 |
+
st.write(f"**Question {i+1}:** {st.session_state['questions'][i]}")
|
| 32 |
+
st.write(f"**Your Answer:** {st.session_state['answers'][i]}")
|
| 33 |
+
st.write(f"**Score:** {st.session_state['scores'][i]}")
|
| 34 |
+
st.write(f"**Feedback:** {st.session_state['feedback'][i]}")
|
| 35 |
+
st.write("---")
|
| 36 |
+
|
| 37 |
+
# Initialize session state
|
| 38 |
+
if 'questions' not in st.session_state:
|
| 39 |
+
st.session_state['questions'] = []
|
| 40 |
+
if 'answers' not in st.session_state:
|
| 41 |
+
st.session_state['answers'] = []
|
| 42 |
+
if 'feedback' not in st.session_state:
|
| 43 |
+
st.session_state['feedback'] = []
|
| 44 |
+
if 'scores' not in st.session_state:
|
| 45 |
+
st.session_state['scores'] = []
|
| 46 |
+
if 'current_question' not in st.session_state:
|
| 47 |
+
st.session_state['current_question'] = 0
|
| 48 |
+
if 'total_questions' not in st.session_state:
|
| 49 |
+
st.session_state['total_questions'] = 10
|
| 50 |
+
if 'question_answered' not in st.session_state:
|
| 51 |
+
st.session_state['question_answered'] = False
|
| 52 |
+
if 'interview_started' not in st.session_state:
|
| 53 |
+
st.session_state['interview_started'] = False
|
| 54 |
+
|
| 55 |
+
st.title("Mock Interview Bot")
|
| 56 |
+
|
| 57 |
+
if not st.session_state['interview_started']:
|
| 58 |
+
roles_and_topics = {
|
| 59 |
+
|
| 60 |
+
"Front-End Developer": ["HTML/CSS", "JavaScript and Frameworks (React, Angular, Vue.js)", "Responsive Design", "Browser Compatibility"],
|
| 61 |
+
"Back-End Developer": ["Server-Side Languages (Node.js, Python, Ruby, PHP)", "Database Management (SQL, NoSQL)", "API Development", "Server and Hosting Management"],
|
| 62 |
+
"Full-Stack Developer": ["Combination of Front-End and Back-End Topics", "Integration of Systems", "DevOps Basics"],
|
| 63 |
+
"Mobile Developer": ["Android Development (Java, Kotlin)", "iOS Development (Swift, Objective-C)", "Cross-Platform Development (Flutter, React Native)"],
|
| 64 |
+
"Data Scientist": ["Statistical Analysis", "Machine Learning Algorithms", "Data Wrangling and Cleaning", "Data Visualization"],
|
| 65 |
+
"Data Analyst": ["Data Collection and Processing", "SQL and Database Querying", "Data Visualization Tools (Tableau, Power BI)", "Basic Statistics"],
|
| 66 |
+
"Machine Learning Engineer": ["Supervised and Unsupervised Learning", "Model Deployment", "Deep Learning", "Natural Language Processing"],
|
| 67 |
+
"DevOps Engineer": ["Continuous Integration/Continuous Deployment (CI/CD)", "Containerization (Docker, Kubernetes)", "Infrastructure as Code (Terraform, Ansible)", "Cloud Platforms (AWS, Azure, Google Cloud)"],
|
| 68 |
+
"Cloud Engineer": ["Cloud Architecture", "Cloud Services (Compute, Storage, Networking)", "Security in the Cloud", "Cost Management"],
|
| 69 |
+
"Cybersecurity Analyst": ["Threat Detection and Mitigation", "Security Protocols and Encryption", "Network Security", "Incident Response"],
|
| 70 |
+
"Penetration Tester": ["Vulnerability Assessment", "Ethical Hacking Techniques", "Security Tools (Metasploit, Burp Suite)", "Report Writing and Documentation"],
|
| 71 |
+
"Project Manager": ["Project Planning and Scheduling", "Risk Management", "Agile and Scrum Methodologies", "Stakeholder Communication"],
|
| 72 |
+
"UX/UI Designer": ["User Research", "Wireframing and Prototyping", "Design Principles", "Usability Testing"],
|
| 73 |
+
"Quality Assurance (QA) Engineer": ["Testing Methodologies", "Automation Testing", "Bug Tracking", "Performance Testing"],
|
| 74 |
+
"Blockchain Developer": ["Blockchain Fundamentals", "Smart Contracts", "Cryptographic Algorithms", "Decentralized Applications (DApps)"],
|
| 75 |
+
"Digital Marketing Specialist": ["SEO/SEM", "Social Media Marketing", "Content Marketing", "Analytics and Reporting"],
|
| 76 |
+
"AI Research Scientist": ["AI Theory", "Algorithm Development", "Neural Networks", "Natural Language Processing"],
|
| 77 |
+
"AI Engineer": ["AI Model Deployment", "Machine Learning Engineering", "Deep Learning", "AI Tools and Frameworks"],
|
| 78 |
+
"Generative AI Specialist (GenAI)": ["Generative Models", "GANs (Generative Adversarial Networks)", "Creative AI Applications", "Ethics in AI"],
|
| 79 |
+
"Generative Business Intelligence Specialist (GenBI)": ["Automated Data Analysis", "Business Intelligence Tools", "Predictive Analytics", "AI in Business Strategy"]
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
}
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
role = st.selectbox('Select Role', list(roles_and_topics.keys()))
|
| 89 |
+
topic = st.selectbox('Select Topic', roles_and_topics[role])
|
| 90 |
+
difficulty_level = st.selectbox("Select difficulty level:", ["Easy", "Medium", "Hard"])
|
| 91 |
+
|
| 92 |
+
if st.button("Start Interview"):
|
| 93 |
+
if role and topic and difficulty_level:
|
| 94 |
+
st.session_state['questions'] = [generate_question(role, topic, difficulty_level) for _ in range(st.session_state['total_questions'])]
|
| 95 |
+
st.session_state['current_question'] = 0
|
| 96 |
+
st.session_state['interview_started'] = True
|
| 97 |
+
st.session_state['question_answered'] = False
|
| 98 |
+
|
| 99 |
+
if st.session_state['interview_started']:
|
| 100 |
+
current_question = st.session_state['current_question']
|
| 101 |
+
if current_question < st.session_state['total_questions']:
|
| 102 |
+
st.write(f"Question {current_question + 1}: {st.session_state['questions'][current_question]}")
|
| 103 |
+
|
| 104 |
+
if not st.session_state['question_answered']:
|
| 105 |
+
answer = st.text_area("Your Answer:", key=f"answer_{current_question}")
|
| 106 |
+
if st.button("Submit Answer"):
|
| 107 |
+
if answer:
|
| 108 |
+
st.session_state['answers'].append(answer)
|
| 109 |
+
score, feedback = evaluate_answer(st.session_state['questions'][current_question], answer)
|
| 110 |
+
st.session_state['scores'].append(score)
|
| 111 |
+
st.session_state['feedback'].append(feedback)
|
| 112 |
+
st.session_state['question_answered'] = True
|
| 113 |
+
st.write(f"Score: {score}")
|
| 114 |
+
st.write(f"Feedback: {feedback}")
|
| 115 |
+
|
| 116 |
+
if st.session_state['question_answered']:
|
| 117 |
+
if st.button("Next Question"):
|
| 118 |
+
st.session_state['current_question'] += 1
|
| 119 |
+
st.session_state['question_answered'] = False
|
| 120 |
+
else:
|
| 121 |
+
st.write("Interview Complete! Generating Report...")
|
| 122 |
+
generate_report()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|