Spaces:
Sleeping
Sleeping
| 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() | |