KhaqanNasir commited on
Commit
65b46a5
Β·
verified Β·
1 Parent(s): 8791658

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -41
app.py CHANGED
@@ -1,14 +1,13 @@
1
- # Save as `interview_copilot.py`
 
 
2
  import streamlit as st
3
- from streamlit_webrtc import webrtc_streamer
4
  from transformers import pipeline
5
- from sentence_transformers import SentenceTransformer
6
- import openai
7
- import whisper
8
  import time
9
  import random
10
 
11
- # Configuration for Streamlit
12
  st.set_page_config(page_title="Interview Copilot", layout="wide")
13
  st.markdown(
14
  """
@@ -23,7 +22,6 @@ st.markdown(
23
  # Page Title
24
  st.title("πŸŽ™οΈ Interview Copilot")
25
  st.write("### Conduct professional mock interviews, receive feedback, and ace your next job opportunity!")
26
- st.image("https://via.placeholder.com/800x200?text=Interview+Copilot", use_column_width=True)
27
 
28
  # Step 1: Input Job Title
29
  st.subheader("Step 1: Enter Job Details")
@@ -42,17 +40,34 @@ if st.button("Start Interview"):
42
  if not job_title or not job_description or not uploaded_cv:
43
  st.error("Please fill in all the required fields (Job Title, Description, CV)!")
44
  else:
45
- # Simulate Interview Start
46
  st.subheader("πŸŽ₯ Live Interview Simulation")
47
  st.write("The interview will begin shortly. Prepare yourself!")
48
  st.write("πŸ‘€ **Bot:** Hello, let’s start the interview!")
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  # Timer
51
  start_time = time.time()
52
  duration = 5 * 60 # 5 minutes
53
- webrtc_streamer(key="camera", rtc_configuration={"iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]})
54
 
55
  # Predefined questions
 
56
  questions = [
57
  "Introduce yourself.",
58
  "Why do you want this job?",
@@ -66,16 +81,9 @@ if st.button("Start Interview"):
66
  "What are your strengths and weaknesses?",
67
  ]
68
 
69
- # Generate AI-based questions using Hugging Face models
70
- question_generator = pipeline("text-generation", model="EleutherAI/gpt-neo-2.7B")
71
- generated_questions = question_generator(
72
- f"Generate 3 interview questions for the role of {job_title} based on this CV:\n{cv_content}",
73
- max_length=50, num_return_sequences=3
74
- )
75
- ai_questions = [q["generated_text"] for q in generated_questions]
76
-
77
- # Combine questions
78
- all_questions = questions + random.sample(technical_questions, 2) + random.sample(non_technical_questions, 2) + ai_questions
79
 
80
  # Conduct interview
81
  responses = []
@@ -84,34 +92,30 @@ if st.button("Start Interview"):
84
  user_response = st.text_area(f"Your Answer to Question {idx + 1}", key=f"response_{idx}")
85
  responses.append(user_response)
86
 
 
87
  if time.time() - start_time > duration:
88
  st.warning("⏱️ Interview time is up!")
89
  break
90
 
91
- # Step 4: Evaluation
92
  st.subheader("πŸ“Š Evaluation")
93
- st.write("Evaluating your performance based on your answers...")
94
 
95
- # Communication Skills Analysis
96
  sentiment_analyzer = pipeline("sentiment-analysis")
97
- sentiment_results = [sentiment_analyzer(response)[0] for response in responses if response]
98
- positive_count = sum(1 for result in sentiment_results if result["label"] == "POSITIVE")
 
 
99
 
100
- # Feedback
101
- score = positive_count * 10 # Simplified scoring
102
- if score >= 70:
103
- st.success(f"πŸŽ‰ Great job! You scored {score}/100. You're ready to ace the interview!")
104
  else:
105
- st.error(f"πŸ™ You scored {score}/100. Here's how you can improve:")
106
- st.write("- Practice communicating your ideas clearly.")
107
- st.write("- Provide detailed examples to technical questions.")
108
- st.write("- Work on your confidence and tone of speech.")
109
-
110
- # CV Recommendations
111
- st.subheader("πŸ“„ CV Recommendations")
112
- st.write("- Add measurable achievements to your CV.")
113
- st.write("- Tailor your CV to match the job description.")
114
-
115
- # Add Graphics and Animation
116
- st.markdown("---")
117
- st.markdown("#### Powered by AI | Built with πŸ’» and Streamlit")
 
1
+ # Install dependencies if running on Colab
2
+ # !pip install streamlit streamlit-webrtc openai openai-whisper transformers sentence-transformers streamlit-lottie
3
+
4
  import streamlit as st
5
+ from streamlit_webrtc import webrtc_streamer, WebRtcMode, RTCConfiguration
6
  from transformers import pipeline
 
 
 
7
  import time
8
  import random
9
 
10
+ # Streamlit Configuration
11
  st.set_page_config(page_title="Interview Copilot", layout="wide")
12
  st.markdown(
13
  """
 
22
  # Page Title
23
  st.title("πŸŽ™οΈ Interview Copilot")
24
  st.write("### Conduct professional mock interviews, receive feedback, and ace your next job opportunity!")
 
25
 
26
  # Step 1: Input Job Title
27
  st.subheader("Step 1: Enter Job Details")
 
40
  if not job_title or not job_description or not uploaded_cv:
41
  st.error("Please fill in all the required fields (Job Title, Description, CV)!")
42
  else:
 
43
  st.subheader("πŸŽ₯ Live Interview Simulation")
44
  st.write("The interview will begin shortly. Prepare yourself!")
45
  st.write("πŸ‘€ **Bot:** Hello, let’s start the interview!")
46
 
47
+ # RTC Configuration for WebRTC
48
+ RTC_CONFIGURATION = RTCConfiguration(
49
+ {
50
+ "iceServers": [{"urls": ["stun:stun.l.google.com:19302"]}]
51
+ }
52
+ )
53
+
54
+ # Activate webcam
55
+ webrtc_streamer(
56
+ key="interview",
57
+ mode=WebRtcMode.SENDRECV,
58
+ rtc_configuration=RTC_CONFIGURATION,
59
+ media_stream_constraints={
60
+ "video": True,
61
+ "audio": True,
62
+ },
63
+ )
64
+
65
  # Timer
66
  start_time = time.time()
67
  duration = 5 * 60 # 5 minutes
 
68
 
69
  # Predefined questions
70
+ st.write("### Interview Questions")
71
  questions = [
72
  "Introduce yourself.",
73
  "Why do you want this job?",
 
81
  "What are your strengths and weaknesses?",
82
  ]
83
 
84
+ # Add random questions to interview
85
+ random_questions = random.sample(technical_questions, 2) + random.sample(non_technical_questions, 2)
86
+ all_questions = questions + random_questions
 
 
 
 
 
 
 
87
 
88
  # Conduct interview
89
  responses = []
 
92
  user_response = st.text_area(f"Your Answer to Question {idx + 1}", key=f"response_{idx}")
93
  responses.append(user_response)
94
 
95
+ # Check if time exceeded
96
  if time.time() - start_time > duration:
97
  st.warning("⏱️ Interview time is up!")
98
  break
99
 
100
+ # Evaluation
101
  st.subheader("πŸ“Š Evaluation")
102
+ st.write("Analyzing your responses...")
103
 
 
104
  sentiment_analyzer = pipeline("sentiment-analysis")
105
+ positive_responses = sum(
106
+ 1 for response in responses if response and sentiment_analyzer(response)[0]["label"] == "POSITIVE"
107
+ )
108
+ score = (positive_responses / len(all_questions)) * 100
109
 
110
+ # Display feedback
111
+ if score > 70:
112
+ st.success(f"πŸŽ‰ Excellent! You scored {score:.2f}/100. You're ready for the job!")
 
113
  else:
114
+ st.error(f"πŸ™ You scored {score:.2f}/100. Here's how you can improve:")
115
+ st.write("- Practice answering common interview questions.")
116
+ st.write("- Provide more detailed responses.")
117
+ st.write("- Speak with confidence and clarity.")
118
+
119
+ st.subheader("πŸ“„ CV Feedback")
120
+ st.write("- Add quantifiable achievements to your CV.")
121
+ st.write("- Tailor your CV to the job description.")