DhruvDecoder commited on
Commit
621167a
·
verified ·
1 Parent(s): 32236d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -182
app.py CHANGED
@@ -1,142 +1,25 @@
1
  import streamlit as st
2
- import openai
3
- from pytube import YouTube
4
  import os
5
- import tempfile
6
- from fpdf import FPDF
7
- # Set your OpenAI API key
8
- openai_api_key = os.environ.get("OPENAI_API_KEY")
9
- openai.api_key = openai_api_key
10
 
11
- def generate_sentiment_score(input_text, parameters):
12
- prompt = f'''
13
- 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.
14
 
15
- 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.
16
-
17
- The parameters to evaluate are:
18
- {', '.join(parameters)}.
19
-
20
- To complete this task, you will:
21
-
22
- 1. Carefully review the provided interview transcript.
23
- 2. Consider phrases, word choices, or patterns of speech that convey positive or negative sentiment for each parameter.
24
- 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.
25
-
26
- Provide your scores in the format: Parameter: Score.
27
- '''
28
-
29
- response = openai.ChatCompletion.create(
30
- model="gpt-3.5-turbo",
31
- temperature=0,
32
- top_p=0.7,
33
- messages=[
34
- {
35
- "role": "system",
36
- "content": prompt
37
- },
38
- {
39
- "role": "user",
40
- "content": input_text
41
- }
42
- ]
43
- )
44
- return response['choices'][0]['message']['content']
45
-
46
- def generate_detailed_feedback(input_text, parameters):
47
- prompt = f'''
48
- As an experienced interview reviewer, provide a detailed analysis of the candidate's responses based on the following parameters: {', '.join(parameters)}.
49
-
50
- 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.
51
- '''
52
-
53
- response = openai.ChatCompletion.create(
54
- model="gpt-3.5-turbo",
55
- temperature=0,
56
- top_p=0.7,
57
- messages=[
58
- {
59
- "role": "system",
60
- "content": prompt
61
- },
62
- {
63
- "role": "user",
64
- "content": input_text
65
- }
66
- ]
67
- )
68
- return response['choices'][0]['message']['content']
69
-
70
- def transcript(video_link):
71
- try:
72
- # Create a YouTube object
73
- yt = YouTube(video_link)
74
-
75
- # Choose the stream with the desired quality and resolution
76
- stream = yt.streams.filter(only_audio=True).first()
77
-
78
- # Download the video to a temporary location
79
- temp_file_path = stream.download()
80
-
81
- print(f"Video '{yt.title}.mp4' downloaded successfully!")
82
-
83
- # Transcribe the video using OpenAI's Whisper
84
- with open(temp_file_path, 'rb') as audio_data:
85
- total_transcript = (openai.Audio.transcribe("whisper-1", audio_data))["text"]
86
- print("Done with the video processing\n")
87
-
88
- # Remove the temporary file
89
- os.remove(temp_file_path)
90
-
91
- return total_transcript
92
-
93
- except Exception as e:
94
- print(f"Error: {e}")
95
- return None
96
 
97
  def main():
98
- st.set_page_config(page_title="Insight Hire", page_icon=":bar_chart:")
99
  st.title("Insight Hire")
100
  st.write("Analyze interview transcripts or videos to gain valuable insights into candidate sentiment.")
101
 
102
- st.sidebar.markdown("## About")
103
- st.sidebar.markdown("""
104
- <div style='color: #1f77b4; font-weight: bold;'>Streamline Your Interview Evaluation</div>
105
- - Get data-driven sentiment scores for key parameters
106
- - Identify top candidates based on sentiment analysis
107
- - Make informed hiring decisions with actionable insights
108
- """, unsafe_allow_html=True)
109
-
110
- st.sidebar.markdown("<hr>", unsafe_allow_html=True) # Horizontal separator
111
-
112
- st.sidebar.markdown("## Tips")
113
- st.sidebar.markdown("""
114
- <div style='color: #2ca02c; font-weight: bold;'>📝 Input Preparation</div>
115
- - Provide clear interview transcripts or valid video links
116
- - Specify relevant parameters for sentiment analysis
117
- """, unsafe_allow_html=True)
118
-
119
- st.sidebar.markdown("<hr>", unsafe_allow_html=True) # Horizontal separator
120
-
121
- st.sidebar.markdown("## About Me")
122
- st.sidebar.markdown("""
123
- <div style='color: #d62728; font-weight: bold;'>👋 Hi, I'm Dhruv!</div>
124
- 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.
125
- """, unsafe_allow_html=True)
126
-
127
  input_option = st.radio("Select input type", ("Text", "YouTube Video Link"))
128
 
129
- input_text = ""
130
  if input_option == "Text":
131
  input_text = st.text_area("Enter the interview transcript:")
132
  else:
133
  video_link = st.text_input("Enter the YouTube video link:")
134
- if video_link:
135
- with st.spinner("Processing video..."):
136
- input_text = transcript(video_link)
137
- if not input_text:
138
- st.error("Error processing the video. Please try again with a different link.")
139
- return
140
 
141
  parameters = st.text_input("Enter the parameters for sentiment analysis (comma-separated):", "Enthusiasm, Communication Skills, Technical Knowledge")
142
  parameters = [param.strip() for param in parameters.split(",")]
@@ -144,66 +27,18 @@ def main():
144
  if st.button("Analyze"):
145
  if input_text and parameters:
146
  with st.spinner("Generating sentiment scores..."):
147
- sentiment_scores = generate_sentiment_score(input_text, parameters)
148
- sentiment_scores = sentiment_scores.strip().split("\n")
149
-
 
 
150
  st.subheader("Sentiment Scores")
151
- valid_scores = []
152
- for score in sentiment_scores:
153
- if ":" in score:
154
- param, score_value = score.split(":")
155
- param = param.strip()
156
- score_value = score_value.strip()
157
- if param in parameters:
158
- try:
159
- score_value = float(score_value.split("/")[0].strip())
160
- valid_scores.append((param, score_value))
161
- if score_value >= 4:
162
- color = "#2ca02c" # Green
163
- elif score_value >= 3:
164
- color = "#ff7f0e" # Orange
165
- else:
166
- color = "#d62728" # Red
167
- st.markdown(f"**{param}**: <span style='color: {color}'>{score_value}/5</span>", unsafe_allow_html=True)
168
- except ValueError:
169
- pass
170
-
171
- if valid_scores:
172
- # Generate detailed feedback
173
- with st.spinner("Generating detailed feedback..."):
174
- detailed_feedback = generate_detailed_feedback(input_text, parameters)
175
- st.subheader("Detailed Feedback")
176
- st.write(detailed_feedback)
177
-
178
- # Provide an option to download detailed feedback as a .txt or .pdf file
179
- temp_txt_path = tempfile.mktemp(suffix=".txt")
180
- with open(temp_txt_path, 'w') as f:
181
- f.write(detailed_feedback)
182
-
183
- st.download_button(
184
- label="Download Detailed Feedback as .txt",
185
- data=open(temp_txt_path, 'r').read(),
186
- file_name="detailed_feedback.txt",
187
- mime="text/plain"
188
- )
189
-
190
- pdf = FPDF()
191
- pdf.add_page()
192
- pdf.set_font("Arial", size=12)
193
- pdf.multi_cell(0, 10, detailed_feedback)
194
-
195
- temp_pdf_path = tempfile.mktemp(suffix=".pdf")
196
- pdf.output(temp_pdf_path)
197
-
198
- with open(temp_pdf_path, "rb") as f:
199
- st.download_button(
200
- label="Download Detailed Feedback as .pdf",
201
- data=f.read(),
202
- file_name="detailed_feedback.pdf",
203
- mime="application/pdf"
204
- )
205
  else:
206
  st.warning("Please provide input and parameters for sentiment analysis.")
207
 
208
  if __name__ == "__main__":
209
- main()
 
 
 
 
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
  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
 
40
  if __name__ == "__main__":
41
+ main()
42
+
43
+
44
+