Hyma7 commited on
Commit
f0b31e5
·
verified ·
1 Parent(s): 627b67f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -9
app.py CHANGED
@@ -46,7 +46,7 @@ def rank_candidates(candidates):
46
  def transcribe_video(video_file):
47
  # Save the uploaded file to a temporary location
48
  with NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video_file:
49
- temp_video_file.write(video_file.read()) # Write video file to the temp file
50
  temp_video_path = temp_video_file.name
51
 
52
  # Load the video and extract audio
@@ -54,28 +54,43 @@ def transcribe_video(video_file):
54
  audio_file = "audio.wav"
55
  video.audio.write_audiofile(audio_file)
56
 
57
- # Perform transcription with Whisper
58
- whisper_model = whisper.load_model("base") # Ensure model is loaded here
59
  transcription = whisper_model.transcribe(audio_file)
60
 
61
- # Clean up temporary files
62
  os.remove(audio_file)
63
  os.remove(temp_video_path)
64
 
65
  return transcription['text']
66
 
67
- # Streamlit app
68
  st.title("AI Role Candidate Screening via Video Interview")
69
 
70
- # Input for the number of candidates
 
 
71
  num_candidates = st.number_input("Enter the number of candidates:", min_value=1, max_value=10, value=1)
72
 
73
  mock_interviews = []
74
  for i in range(num_candidates):
75
- video_file = st.file_uploader(f"Upload interview video for Candidate {i+1}:", type=["mp4", "mov", "avi"], key=f"video_{i}")
 
 
 
 
 
 
 
 
 
 
 
76
  if video_file:
77
  st.write(f"Processing video for Candidate {i+1}...")
78
- transcription = transcribe_video(video_file)
 
 
 
 
79
  st.write(f"Transcript for Candidate {i+1}: {transcription}")
80
  mock_interviews.append({"name": f"Candidate {i+1}", "response": transcription})
81
 
@@ -100,4 +115,4 @@ if st.button('Analyze Responses'):
100
  st.write(f"Average Score: {candidate['avg_score']:.2f}")
101
  st.write(f"Scores: {candidate['scores']}")
102
  else:
103
- st.write("Please upload videos for all candidates.")
 
46
  def transcribe_video(video_file):
47
  # Save the uploaded file to a temporary location
48
  with NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video_file:
49
+ temp_video_file.write(video_file.read())
50
  temp_video_path = temp_video_file.name
51
 
52
  # Load the video and extract audio
 
54
  audio_file = "audio.wav"
55
  video.audio.write_audiofile(audio_file)
56
 
57
+ whisper_model = whisper.load_model("base")
 
58
  transcription = whisper_model.transcribe(audio_file)
59
 
 
60
  os.remove(audio_file)
61
  os.remove(temp_video_path)
62
 
63
  return transcription['text']
64
 
65
+
66
  st.title("AI Role Candidate Screening via Video Interview")
67
 
68
+ default_videos = ["Unlocking AI_ Insights from a Machine Learning Engineer.mp4", "Navigating Ethical Challenges in AI.mp4"]
69
+
70
+
71
  num_candidates = st.number_input("Enter the number of candidates:", min_value=1, max_value=10, value=1)
72
 
73
  mock_interviews = []
74
  for i in range(num_candidates):
75
+ st.write(f"### Candidate {i+1}")
76
+
77
+ # Provide options to either upload a video or use a default video
78
+ use_default = st.checkbox(f"Use default video for Candidate {i+1}?", key=f"default_{i}")
79
+
80
+ if use_default:
81
+ video_file_path = default_videos[i % len(default_videos)] # Cycle through default videos
82
+ st.write(f"Using default video: {video_file_path}")
83
+ video_file = open(video_file_path, "rb") # Open the default video file as binary
84
+ else:
85
+ video_file = st.file_uploader(f"Upload interview video for Candidate {i+1}:", type=["mp4", "mov", "avi"], key=f"video_{i}")
86
+
87
  if video_file:
88
  st.write(f"Processing video for Candidate {i+1}...")
89
+ if not use_default:
90
+ transcription = transcribe_video(video_file) # For uploaded videos
91
+ else:
92
+ transcription = transcribe_video(video_file) # For default videos
93
+
94
  st.write(f"Transcript for Candidate {i+1}: {transcription}")
95
  mock_interviews.append({"name": f"Candidate {i+1}", "response": transcription})
96
 
 
115
  st.write(f"Average Score: {candidate['avg_score']:.2f}")
116
  st.write(f"Scores: {candidate['scores']}")
117
  else:
118
+ st.write("Please upload videos for all candidates.")