File size: 2,651 Bytes
ae09409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from openai import OpenAI
# from dotenv import load_dotenv
import yt_dlp 
import modal
import torch

class Summarizer:
    def __init__(self):
        self.system='''You are an intelligent assistant working for a company that builds advanced tools to automate real hiring decisions. Your task is to analyze speech-to-text transcripts from candidate interviews. For each candidate’s response, you will:



                        Provide a clear and concise summary of what the candidate said.



                        Identify the candidate’s motivation and key skills expressed in their speech.



                        Highlight any additional insights or relevant observations that could assist recruiters in making informed hiring decisions.



                        Focus on delivering objective, actionable, and relevant information that captures the candidate’s potential skills'''
        
        self.transcriber="gpt-4o-transcribe"
        self.summarizer="gpt-4.1-mini"
        self.Accentizer= modal.Cls.lookup("ClassifierAudio", "Accentizer")
        self.client=OpenAI()
    def download_audio(self,url, output_path='audio'):
        import yt_dlp 
        ydl_opts = {
            'format': 'bestaudio/best',
            'outtmpl': output_path,
            'postprocessors': [{
                'key': 'FFmpegExtractAudio',
                'preferredcodec': 'mp3',  # or 'wav'
                'preferredquality': '192',
            }],
        }

        with yt_dlp.YoutubeDL(ydl_opts) as ydl:
            ydl.download([url])   
    def classify(self,url):
        raw= self.Accentizer.classify.remote(url)
        accent = raw["label"][0] if isinstance(raw["label"], list) else str(raw["label"])
        score = raw["score"].item() if isinstance(raw["score"], torch.Tensor) else float(raw["score"])
        return {
        "label": accent,
        "score": round(score, 4)
    }
        return result
    def summarize(self,url):
        self.download_audio(url=url)
        audio_file=open("./audio.mp3", "rb")
        transcription = self.client.audio.transcriptions.create(
                model=self.transcriber, 
                file=audio_file
            )   
        user_prompt="Here is transcription of the audio \n "
        user_prompt+=transcription.text
        prompts = [
        {"role": "system", "content": self.system},
        {"role": "user", "content": user_prompt}
        ]
        chat=self.client.chat.completions.create(
        model=self.summarizer,
        messages=prompts
        )
        return chat.choices[0].message.content