import streamlit as st import requests import os from pytube import YouTube import tempfile from fpdf import FPDF import time from together import Together # API configurations together_api_key = os.environ.get('TOGETHER_API_KEY') assembly_api_key = os.environ.get('ASSEMBLYAI_API_KEY') client = Together(api_key=together_api_key) assembly_base_url = "https://api.assemblyai.com/v2" assembly_headers = { "authorization": assembly_api_key } def generate_sentiment_score(input_text, parameters): prompt = f''' You are an experienced interview reviewer and consultant for a reputable company. Your role is to evaluate the sentiment displayed by job candidates during their interviews based on the transcripts of their responses. The hiring team has provided you with an interview transcript and has asked you to analyze the candidate's sentiment for the following parameters: {', '.join(parameters)}. Your assessment will help the team make more informed hiring decisions and identify candidates who demonstrate genuine positive sentiment towards the role and the company. The parameters to evaluate are: {', '.join(parameters)}. To complete this task, you will: 1. Carefully review the provided interview transcript. 2. Consider phrases, word choices, or patterns of speech that convey positive or negative sentiment for each parameter. 3. Based on your analysis, provide a sentiment score on a scale of 1-5 for each parameter, with 1 being extremely negative and 5 being extremely positive. Provide your scores in the format: Parameter: (Score). 4. The output should be like a professional interview reviewer(HR) Here's the transcript: {input_text} ''' response = client.chat.completions.create( model="meta-llama/Llama-3-70b-chat-hf", messages=[ {"role": "system", "content": "You are an AI assistant that analyzes interview transcripts and provides sentiment scores."}, {"role": "user", "content": prompt} ], temperature=0.1, max_tokens=1024, top_p=0.7 ) return response.choices[0].message.content def generate_detailed_feedback(input_text, parameters): prompt = f''' As an experienced interview reviewer, provide a detailed analysis of the candidate's responses based on the following parameters: {', '.join(parameters)}. Include specific examples, quotes, and adjectives from the transcript that support your analysis.(no need to provide scores)Offer actionable insights and recommendations for the hiring team to make informed decisions. Summarize the candidate's overall sentiment and demeanor. Here's the transcript: {input_text} ''' response = client.chat.completions.create( model="meta-llama/Llama-3-70b-chat-hf", messages=[ {"role": "system", "content": "You are an AI assistant that provides detailed feedback on interview transcripts."}, {"role": "user", "content": prompt} ], temperature=0.3, max_tokens=2048, top_p=0.7 ) return response.choices[0].message.content def upload_to_assemblyai(file_path): with open(file_path, "rb") as f: response = requests.post(f"{assembly_base_url}/upload", headers=assembly_headers, data=f) return response.json().get("upload_url") def transcribe_with_assemblyai(upload_url): data = { "audio_url": upload_url } response = requests.post(f"{assembly_base_url}/transcript", json=data, headers=assembly_headers) transcript_id = response.json().get("id") while True: response = requests.get(f"{assembly_base_url}/transcript/{transcript_id}", headers=assembly_headers) result = response.json() if result['status'] == 'completed': return result['text'] elif result['status'] == 'failed': raise Exception("Transcription failed") time.sleep(5) def transcript(video_link): try: yt = YouTube(video_link) stream = yt.streams.filter(only_audio=True).first() temp_file_path = tempfile.mktemp(suffix=".mp4") stream.download(output_path=os.path.dirname(temp_file_path), filename=os.path.basename(temp_file_path)) print(f"Video '{yt.title}' downloaded successfully!") upload_url = upload_to_assemblyai(temp_file_path) transcription_text = transcribe_with_assemblyai(upload_url) os.remove(temp_file_path) return transcription_text except Exception as e: print(f"Error: {e}") return None def main(): st.set_page_config(page_title="Insight Hire", page_icon=":bar_chart:") st.title("Insight Hire") st.write("Analyze interview transcripts or videos to gain valuable insights into candidate sentiment.") st.sidebar.markdown("## About") st.sidebar.markdown("""