Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,68 +1,59 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
-
from pytube import YouTube
|
| 5 |
import tempfile
|
| 6 |
from fpdf import FPDF
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
together_api_key = os.environ.get("TOGETHER_API_KEY")
|
| 10 |
-
url = "https://api.together.xyz/inference"
|
| 11 |
headers = {
|
| 12 |
"Authorization": f"Bearer {together_api_key}",
|
| 13 |
"Content-Type": "application/json"
|
| 14 |
}
|
| 15 |
-
model = "togethercomputer/llama-2-70b-chat"
|
| 16 |
|
| 17 |
def generate_sentiment_score(input_text, parameters):
|
| 18 |
prompt = f'''
|
| 19 |
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.
|
| 20 |
-
The
|
| 21 |
-
|
| 22 |
-
{', '.join(parameters)}.
|
| 23 |
-
To complete this task, you will:
|
| 24 |
-
1. Carefully review the provided interview transcript.
|
| 25 |
-
2. Consider phrases, word choices, or patterns of speech that convey positive or negative sentiment for each parameter.
|
| 26 |
-
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.
|
| 27 |
-
Provide your scores in the format: Parameter: Score.
|
| 28 |
'''
|
| 29 |
data = {
|
| 30 |
-
"model":
|
| 31 |
-
"prompt":
|
| 32 |
"temperature": 0.0,
|
| 33 |
"max_tokens": 1024
|
| 34 |
}
|
| 35 |
-
response = requests.post(
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
def generate_detailed_feedback(input_text, parameters):
|
| 39 |
prompt = f'''
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
Include specific examples, quotes, and adjectives from the transcript that support your analysis. Offer actionable insights and recommendations for the hiring team to make informed decisions. Summarize the candidate's overall sentiment and demeanor.
|
| 43 |
'''
|
| 44 |
data = {
|
| 45 |
-
"model":
|
| 46 |
-
"prompt":
|
| 47 |
"temperature": 0.0,
|
| 48 |
"max_tokens": 1024
|
| 49 |
}
|
| 50 |
-
response = requests.post(
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
def transcript(video_link):
|
| 54 |
try:
|
| 55 |
yt = YouTube(video_link)
|
| 56 |
stream = yt.streams.filter(only_audio=True).first()
|
| 57 |
temp_file_path = stream.download()
|
| 58 |
-
print(f"Video '{yt.title}.mp4' downloaded successfully!")
|
| 59 |
with open(temp_file_path, 'rb') as audio_data:
|
| 60 |
-
total_transcript =
|
| 61 |
-
"https://api.together.xyz/audio/transcribe",
|
| 62 |
-
headers=headers,
|
| 63 |
-
files={"file": audio_data}
|
| 64 |
-
).json()["text"]
|
| 65 |
-
print("Done with the video processing\n")
|
| 66 |
os.remove(temp_file_path)
|
| 67 |
return total_transcript
|
| 68 |
except Exception as e:
|
|
@@ -74,29 +65,6 @@ def main():
|
|
| 74 |
st.title("Insight Hire")
|
| 75 |
st.write("Analyze interview transcripts or videos to gain valuable insights into candidate sentiment.")
|
| 76 |
|
| 77 |
-
st.sidebar.markdown("## About")
|
| 78 |
-
st.sidebar.markdown("""
|
| 79 |
-
<div style='color: #1f77b4; font-weight: bold;'>Streamline Your Interview Evaluation</div>
|
| 80 |
-
- Get data-driven sentiment scores for key parameters
|
| 81 |
-
- Identify top candidates based on sentiment analysis
|
| 82 |
-
- Make informed hiring decisions with actionable insights
|
| 83 |
-
""", unsafe_allow_html=True)
|
| 84 |
-
|
| 85 |
-
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
| 86 |
-
st.sidebar.markdown("## Tips")
|
| 87 |
-
st.sidebar.markdown("""
|
| 88 |
-
<div style='color: #2ca02c; font-weight: bold;'>📝 Input Preparation</div>
|
| 89 |
-
- Provide clear interview transcripts or valid video links
|
| 90 |
-
- Specify relevant parameters for sentiment analysis
|
| 91 |
-
""", unsafe_allow_html=True)
|
| 92 |
-
|
| 93 |
-
st.sidebar.markdown("<hr>", unsafe_allow_html=True)
|
| 94 |
-
st.sidebar.markdown("## About Me")
|
| 95 |
-
st.sidebar.markdown("""
|
| 96 |
-
<div style='color: #d62728; font-weight: bold;'>👋 Hi, I'm Dhruv!</div>
|
| 97 |
-
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.
|
| 98 |
-
""", unsafe_allow_html=True)
|
| 99 |
-
|
| 100 |
input_option = st.radio("Select input type", ("Text", "YouTube Video Link"))
|
| 101 |
|
| 102 |
input_text = ""
|
|
@@ -120,7 +88,6 @@ def main():
|
|
| 120 |
sentiment_scores = generate_sentiment_score(input_text, parameters)
|
| 121 |
sentiment_scores = sentiment_scores.strip().split("\n")
|
| 122 |
st.subheader("Sentiment Scores")
|
| 123 |
-
valid_scores = []
|
| 124 |
for score in sentiment_scores:
|
| 125 |
if ":" in score:
|
| 126 |
param, score_value = score.split(":")
|
|
@@ -129,7 +96,6 @@ def main():
|
|
| 129 |
if param in parameters:
|
| 130 |
try:
|
| 131 |
score_value = float(score_value.split("/")[0].strip())
|
| 132 |
-
valid_scores.append((param, score_value))
|
| 133 |
if score_value >= 4:
|
| 134 |
color = "#2ca02c"
|
| 135 |
elif score_value >= 3:
|
|
@@ -145,21 +111,26 @@ def main():
|
|
| 145 |
detailed_feedback = generate_detailed_feedback(input_text, parameters)
|
| 146 |
st.subheader("Detailed Feedback")
|
| 147 |
st.write(detailed_feedback)
|
|
|
|
| 148 |
temp_txt_path = tempfile.mktemp(suffix=".txt")
|
| 149 |
with open(temp_txt_path, 'w') as f:
|
| 150 |
f.write(detailed_feedback)
|
|
|
|
| 151 |
st.download_button(
|
| 152 |
label="Download Detailed Feedback as .txt",
|
| 153 |
data=open(temp_txt_path, 'r').read(),
|
| 154 |
file_name="detailed_feedback.txt",
|
| 155 |
mime="text/plain"
|
| 156 |
)
|
|
|
|
| 157 |
pdf = FPDF()
|
| 158 |
pdf.add_page()
|
| 159 |
pdf.set_font("Arial", size=12)
|
| 160 |
pdf.multi_cell(0, 10, detailed_feedback)
|
|
|
|
| 161 |
temp_pdf_path = tempfile.mktemp(suffix=".pdf")
|
| 162 |
pdf.output(temp_pdf_path)
|
|
|
|
| 163 |
with open(temp_pdf_path, "rb") as f:
|
| 164 |
st.download_button(
|
| 165 |
label="Download Detailed Feedback as .pdf",
|
|
@@ -174,4 +145,7 @@ if __name__ == "__main__":
|
|
| 174 |
main()
|
| 175 |
|
| 176 |
|
|
|
|
|
|
|
|
|
|
| 177 |
|
|
|
|
|
|
|
| 1 |
import requests
|
| 2 |
import os
|
|
|
|
| 3 |
import tempfile
|
| 4 |
from fpdf import FPDF
|
| 5 |
+
import streamlit as st
|
| 6 |
+
from pytube import YouTube
|
| 7 |
|
| 8 |
+
os.environ['TOGETHER_API_KEY'] = 'your_together_api_key_here'
|
| 9 |
together_api_key = os.environ.get("TOGETHER_API_KEY")
|
|
|
|
| 10 |
headers = {
|
| 11 |
"Authorization": f"Bearer {together_api_key}",
|
| 12 |
"Content-Type": "application/json"
|
| 13 |
}
|
|
|
|
| 14 |
|
| 15 |
def generate_sentiment_score(input_text, parameters):
|
| 16 |
prompt = f'''
|
| 17 |
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.
|
| 18 |
+
The parameters to evaluate are: {', '.join(parameters)}.
|
| 19 |
+
Provide a sentiment score on a scale of 1-5 for each parameter.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
'''
|
| 21 |
data = {
|
| 22 |
+
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 23 |
+
"prompt": prompt,
|
| 24 |
"temperature": 0.0,
|
| 25 |
"max_tokens": 1024
|
| 26 |
}
|
| 27 |
+
response = requests.post("https://api.together.xyz/inference", headers=headers, json=data)
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
return response.json()['output']['choices'][0]['text']
|
| 30 |
+
else:
|
| 31 |
+
print(f"Error: {response.status_code} - {response.text}")
|
| 32 |
|
| 33 |
def generate_detailed_feedback(input_text, parameters):
|
| 34 |
prompt = f'''
|
| 35 |
+
Provide a detailed analysis of the candidate's responses based on the following parameters: {', '.join(parameters)}.
|
| 36 |
+
Include specific examples, quotes, and adjectives from the transcript that support your analysis. Summarize the candidate's overall sentiment and demeanor.
|
|
|
|
| 37 |
'''
|
| 38 |
data = {
|
| 39 |
+
"model": "mistralai/Mixtral-8x7B-Instruct-v0.1",
|
| 40 |
+
"prompt": prompt,
|
| 41 |
"temperature": 0.0,
|
| 42 |
"max_tokens": 1024
|
| 43 |
}
|
| 44 |
+
response = requests.post("https://api.together.xyz/inference", headers=headers, json=data)
|
| 45 |
+
if response.status_code == 200:
|
| 46 |
+
return response.json()['output']['choices'][0]['text']
|
| 47 |
+
else:
|
| 48 |
+
print(f"Error: {response.status_code} - {response.text}")
|
| 49 |
|
| 50 |
def transcript(video_link):
|
| 51 |
try:
|
| 52 |
yt = YouTube(video_link)
|
| 53 |
stream = yt.streams.filter(only_audio=True).first()
|
| 54 |
temp_file_path = stream.download()
|
|
|
|
| 55 |
with open(temp_file_path, 'rb') as audio_data:
|
| 56 |
+
total_transcript = (openai.Audio.transcribe("whisper-1", audio_data))["text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
os.remove(temp_file_path)
|
| 58 |
return total_transcript
|
| 59 |
except Exception as e:
|
|
|
|
| 65 |
st.title("Insight Hire")
|
| 66 |
st.write("Analyze interview transcripts or videos to gain valuable insights into candidate sentiment.")
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
input_option = st.radio("Select input type", ("Text", "YouTube Video Link"))
|
| 69 |
|
| 70 |
input_text = ""
|
|
|
|
| 88 |
sentiment_scores = generate_sentiment_score(input_text, parameters)
|
| 89 |
sentiment_scores = sentiment_scores.strip().split("\n")
|
| 90 |
st.subheader("Sentiment Scores")
|
|
|
|
| 91 |
for score in sentiment_scores:
|
| 92 |
if ":" in score:
|
| 93 |
param, score_value = score.split(":")
|
|
|
|
| 96 |
if param in parameters:
|
| 97 |
try:
|
| 98 |
score_value = float(score_value.split("/")[0].strip())
|
|
|
|
| 99 |
if score_value >= 4:
|
| 100 |
color = "#2ca02c"
|
| 101 |
elif score_value >= 3:
|
|
|
|
| 111 |
detailed_feedback = generate_detailed_feedback(input_text, parameters)
|
| 112 |
st.subheader("Detailed Feedback")
|
| 113 |
st.write(detailed_feedback)
|
| 114 |
+
|
| 115 |
temp_txt_path = tempfile.mktemp(suffix=".txt")
|
| 116 |
with open(temp_txt_path, 'w') as f:
|
| 117 |
f.write(detailed_feedback)
|
| 118 |
+
|
| 119 |
st.download_button(
|
| 120 |
label="Download Detailed Feedback as .txt",
|
| 121 |
data=open(temp_txt_path, 'r').read(),
|
| 122 |
file_name="detailed_feedback.txt",
|
| 123 |
mime="text/plain"
|
| 124 |
)
|
| 125 |
+
|
| 126 |
pdf = FPDF()
|
| 127 |
pdf.add_page()
|
| 128 |
pdf.set_font("Arial", size=12)
|
| 129 |
pdf.multi_cell(0, 10, detailed_feedback)
|
| 130 |
+
|
| 131 |
temp_pdf_path = tempfile.mktemp(suffix=".pdf")
|
| 132 |
pdf.output(temp_pdf_path)
|
| 133 |
+
|
| 134 |
with open(temp_pdf_path, "rb") as f:
|
| 135 |
st.download_button(
|
| 136 |
label="Download Detailed Feedback as .pdf",
|
|
|
|
| 145 |
main()
|
| 146 |
|
| 147 |
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
|
| 151 |
|