Spaces:
Sleeping
Sleeping
File size: 9,507 Bytes
795c8db 621167a b05d8f3 795c8db 788f03c 795c8db 3d96031 b05d8f3 3d96031 795c8db 3d96031 788f03c b05d8f3 788f03c 795c8db 3d96031 8b784cc 795c8db 3d96031 795c8db 3d96031 fbef259 3d96031 795c8db 3d96031 788f03c 795c8db 3d96031 795c8db 3d96031 795c8db 3d96031 41d9ca2 3d96031 795c8db 3d96031 795c8db 788f03c 3d96031 795c8db 3d96031 795c8db 788f03c 795c8db 788f03c b05d8f3 788f03c b05d8f3 795c8db b05d8f3 788f03c b05d8f3 788f03c b05d8f3 788f03c b05d8f3 3d96031 788f03c 3d96031 788f03c b05d8f3 3d96031 | 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | 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("""
<div style='color: #1f77b4; font-weight: bold;'>Streamline Your Interview Evaluation</div>
- Get data-driven sentiment scores for key parameters
- Identify top candidates based on sentiment analysis
- Make informed hiring decisions with actionable insights
""", unsafe_allow_html=True)
st.sidebar.markdown("<hr>", unsafe_allow_html=True) # Horizontal separator
st.sidebar.markdown("## Tips")
st.sidebar.markdown("""
<div style='color: #2ca02c; font-weight: bold;'>📝 Input Preparation</div>
- Provide clear interview transcripts or valid video links
- Specify relevant parameters for sentiment analysis
""", unsafe_allow_html=True)
st.sidebar.markdown("<hr>", unsafe_allow_html=True) # Horizontal separator
st.sidebar.markdown("## About Me")
st.sidebar.markdown("""
<div style='color: #d62728; font-weight: bold;'>👋 Hi, I'm Dhruv!</div>
I want to make a real impact in the field of AI/ML . My main interest lies in model building and deployment. I'm passionate about leveraging cutting-edge technologies to solve real-world problems.
""", unsafe_allow_html=True)
input_option = st.radio("Select input type", ("Text", "YouTube Video Link"))
input_text = ""
if input_option == "Text":
input_text = st.text_area("Enter the interview transcript:")
else:
video_link = st.text_input("Enter the YouTube video link:")
if video_link:
with st.spinner("Processing video..."):
input_text = transcript(video_link)
if not input_text:
st.error("Error processing the video. Please try again with a different link.")
return
parameters = st.text_input("Enter the parameters for sentiment analysis (comma-separated):", "Enthusiasm, Communication Skills, Technical Knowledge")
parameters = [param.strip() for param in parameters.split(",")]
if st.button("Analyze"):
if input_text and parameters:
with st.spinner("Generating sentiment scores..."):
sentiment_scores = generate_sentiment_score(input_text, parameters)
st.subheader("Sentiment Scores")
st.write(sentiment_scores)
# Parse and display scores (adjust as needed based on the model's output format)
scores = [line.split(":") for line in sentiment_scores.split("\n") if ":" in line]
for param, score in scores:
param = param.strip()
try:
score = float(score.strip())
if score >= 4:
color = "#2ca02c" # Green
elif score >= 3:
color = "#ff7f0e" # Orange
else:
color = "#d62728" # Red
st.markdown(f"**{param}**: <span style='color: {color}'>{score}/5</span>", unsafe_allow_html=True)
except ValueError:
pass
# Generate detailed feedback
with st.spinner("Generating detailed feedback..."):
detailed_feedback = generate_detailed_feedback(input_text, parameters)
st.subheader("Detailed Feedback")
st.write(detailed_feedback)
# Provide an option to download detailed feedback as a .txt or .pdf file
temp_txt_path = tempfile.mktemp(suffix=".txt")
with open(temp_txt_path, 'w') as f:
f.write(detailed_feedback)
st.download_button(
label="Download Detailed Feedback as .txt",
data=open(temp_txt_path, 'r').read(),
file_name="detailed_feedback.txt",
mime="text/plain"
)
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=12)
pdf.multi_cell(0, 10, detailed_feedback)
temp_pdf_path = tempfile.mktemp(suffix=".pdf")
pdf.output(temp_pdf_path)
with open(temp_pdf_path, "rb") as f:
st.download_button(
label="Download Detailed Feedback as .pdf",
data=f.read(),
file_name="detailed_feedback.pdf",
mime="application/pdf"
)
else:
st.warning("Please provide input and parameters for sentiment analysis.")
if __name__ == "__main__":
main() |