DhruvDecoder commited on
Commit
788f03c
·
verified ·
1 Parent(s): 621167a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +145 -12
app.py CHANGED
@@ -1,25 +1,115 @@
1
  import streamlit as st
2
  import requests
3
  import os
 
 
 
4
 
5
- API_URL = "https://api-inference.huggingface.co/models/meta-llama/Llama-2-7b-chat-hf"
6
- headers = {"Authorization": f"Bearer {os.getenv('HUGGINGFACE_API_KEY')}"}
 
 
 
 
 
 
7
 
8
- def query(payload):
9
- response = requests.post(API_URL, headers=headers, json=payload)
10
- return response.json()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  def main():
 
13
  st.title("Insight Hire")
14
  st.write("Analyze interview transcripts or videos to gain valuable insights into candidate sentiment.")
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  input_option = st.radio("Select input type", ("Text", "YouTube Video Link"))
17
 
 
18
  if input_option == "Text":
19
  input_text = st.text_area("Enter the interview transcript:")
20
  else:
21
  video_link = st.text_input("Enter the YouTube video link:")
22
- input_text = "Mock transcript from YouTube" # Replace with actual transcript function
 
 
 
 
 
23
 
24
  parameters = st.text_input("Enter the parameters for sentiment analysis (comma-separated):", "Enthusiasm, Communication Skills, Technical Knowledge")
25
  parameters = [param.strip() for param in parameters.split(",")]
@@ -27,13 +117,56 @@ def main():
27
  if st.button("Analyze"):
28
  if input_text and parameters:
29
  with st.spinner("Generating sentiment scores..."):
30
- payload = {
31
- "inputs": 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)}.",
32
- "parameters": parameters
33
- }
34
- sentiment_scores = query(payload)
35
  st.subheader("Sentiment Scores")
36
- st.write(sentiment_scores)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  else:
38
  st.warning("Please provide input and parameters for sentiment analysis.")
39
 
 
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
+ # Set your Together.AI API key
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 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.
21
+ The parameters to evaluate are:
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": model,
31
+ "prompt": f"[INST]{prompt}\n{input_text}[/INST]",
32
+ "temperature": 0.0,
33
+ "max_tokens": 1024
34
+ }
35
+ response = requests.post(url, headers=headers, json=data)
36
+ return response.json()['output']['choices'][0]['text']
37
+
38
+ def generate_detailed_feedback(input_text, parameters):
39
+ prompt = f'''
40
+ As an experienced interview reviewer, provide a detailed analysis of the candidate's responses based on the following parameters: {', '.join(parameters)}.
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": model,
46
+ "prompt": f"[INST]{prompt}\n{input_text}[/INST]",
47
+ "temperature": 0.0,
48
+ "max_tokens": 1024
49
+ }
50
+ response = requests.post(url, headers=headers, json=data)
51
+ return response.json()['output']['choices'][0]['text']
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 = requests.post(
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:
69
+ print(f"Error: {e}")
70
+ return None
71
 
72
  def main():
73
+ st.set_page_config(page_title="Insight Hire", page_icon=":bar_chart:")
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 = ""
103
  if input_option == "Text":
104
  input_text = st.text_area("Enter the interview transcript:")
105
  else:
106
  video_link = st.text_input("Enter the YouTube video link:")
107
+ if video_link:
108
+ with st.spinner("Processing video..."):
109
+ input_text = transcript(video_link)
110
+ if not input_text:
111
+ st.error("Error processing the video. Please try again with a different link.")
112
+ return
113
 
114
  parameters = st.text_input("Enter the parameters for sentiment analysis (comma-separated):", "Enthusiasm, Communication Skills, Technical Knowledge")
115
  parameters = [param.strip() for param in parameters.split(",")]
 
117
  if st.button("Analyze"):
118
  if input_text and parameters:
119
  with st.spinner("Generating sentiment scores..."):
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(":")
127
+ param = param.strip()
128
+ score_value = score_value.strip()
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:
136
+ color = "#ff7f0e"
137
+ else:
138
+ color = "#d62728"
139
+ st.markdown(f"**{param}**: <span style='color: {color}'>{score_value}/5</span>", unsafe_allow_html=True)
140
+ except ValueError:
141
+ pass
142
+
143
+ if valid_scores:
144
+ with st.spinner("Generating detailed feedback..."):
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",
166
+ data=f.read(),
167
+ file_name="detailed_feedback.pdf",
168
+ mime="application/pdf"
169
+ )
170
  else:
171
  st.warning("Please provide input and parameters for sentiment analysis.")
172