Spaces:
Sleeping
Sleeping
File size: 5,373 Bytes
8468f4a 058d18a 0b60a6f e099a94 0b60a6f 058d18a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 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 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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
import streamlit as st
from st_audiorec import st_audiorec
import speech_recognition as sr
import tempfile
import os
from dotenv import load_dotenv
import google.generativeai as genai
# ββββββββββββββββββββββββββββββββ
# Load API Keys & Configure Gemini
# ββββββββββββββββββββββββββββββββ
load_dotenv()
genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
# ββββββββββββββββββββββββββββββββ
# AI Prompt Functions
# ββββββββββββββββββββββββββββββββ
def get_follow_up_questions(transcript):
prompt = f"""
You are an AI interview assistant. Given the candidate's answer below, generate 3 insightful follow-up interview questions the interviewer should ask next. Please note, the input might also be the interviewer's question. If that is the case, ignore or do not respond. Rate the Candidate's answer too.
Candidate's response:
\"\"\"{transcript}\"\"\"
Response Rating:
Interviewer questions:
"""
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content(prompt)
return response.text.strip()
def get_final_report(transcript):
prompt = f"""
You are an AI interview assistant. Given the candidate's answer below, generate a report summarizing the candidate's responses, suitability, and overall performance.
Candidate's response:
\"\"\"{transcript}\"\"\"
Candidate Rating:
Interviewer Summary:
"""
model = genai.GenerativeModel('gemini-1.5-flash')
response = model.generate_content(prompt)
return response.text.strip()
# ββββββββββββββββββββββββββββββββ
# Streamlit UI
# ββββββββββββββββββββββββββββββββ
st.set_page_config(page_title="HireScope AI - Audio Transcriber", layout="centered")
st.markdown("<style>.css-1egvi7u {margin-top: -3rem;}</style>", unsafe_allow_html=True)
st.markdown("<style>.stAudio {height: 45px;}</style>", unsafe_allow_html=True)
st.markdown("<style>.css-v37k9u a, .css-nlntq9 a {color: #ff4c4b;}</style>", unsafe_allow_html=True)
# Initialize transcript history
if "transcript_log" not in st.session_state:
st.session_state.transcript_log = ""
if "final_report" not in st.session_state:
st.session_state.final_report = ""
def hirescope_transcriber():
st.title('ποΈ HireScope AI')
st.markdown("Record your voice to get real-time transcription and AI suggestions.")
st.markdown("For the local app version, please visit https://github.com/JishnuSetia/HireScopeAI and follow the instructions")
st.subheader("Instructions for Use:")
st.markdown("- To ask a question, start recording your audio and also record candidate answer")
st.markdown("- Stop recording when done")
st.markdown("- Wait for a few seconds and AI will give you suggestions")
st.markdown("- At the end of the interview, you can export the Transcript and an AI Generated Report")
st.markdown("- You may have issues with audio input due to JavaScript. Preferably, please use the local version (https://github.com/JishnuSetia/HireScopeAI) as that can work with no potential issues at all")
wav_audio_data = st_audiorec()
if wav_audio_data is not None:
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as f:
f.write(wav_audio_data)
temp_wav_path = f.name
recognizer = sr.Recognizer()
with sr.AudioFile(temp_wav_path) as source:
audio = recognizer.record(source)
try:
text = recognizer.recognize_google(audio)
ai = get_follow_up_questions(text)
# Append to transcript log
st.session_state.transcript_log += f"Candidate: {text}\n\nAI: {ai}\n\n"
except sr.UnknownValueError:
st.session_state.transcript_log += "[Unintelligible Audio]\n\n"
except sr.RequestError as e:
st.error(f"Could not request results; {e}")
# Display complete transcript log (non-editable)
st.subheader("π Transcript Log")
st.text_area("Transcription", st.session_state.transcript_log, height=300, disabled=True)
# Export Buttons
st.subheader("π€ Export Options")
col1, col2 = st.columns(2)
with col1:
st.download_button(
label="Download Transcript (.txt)",
data=st.session_state.transcript_log,
file_name="hirescope_transcript.txt",
mime="text/plain"
)
with col2:
if st.button("Generate Final Report"):
with st.spinner("Generating summary report..."):
st.session_state.final_report = get_final_report(st.session_state.transcript_log)
st.success("Summary ready! Click below to download.")
if st.session_state.final_report:
st.download_button(
label="Download Final Report (.txt)",
data=st.session_state.final_report,
file_name="hirescope_final_report.txt",
mime="text/plain"
)
# Run the app
if __name__ == '__main__':
hirescope_transcriber()
|