import os import yt_dlp from openai import OpenAI client = OpenAI( base_url="https://api.studio.nebius.ai/v1/", api_key=os.environ.get("NEBIUS_API_KEY") ) def transcribe_from_url(link:str) -> str: tmp = "/tmp/reel_audio.m4a" ydl_opts = { "format": "m4a/bestaudio/best", "outtmpl": tmp, "quiet": True, } try: yt_dlp.YoutubeDL(ydl_opts).download([link]) except Exception: return "" # Nebius ASR try: with open(tmp, "rb") as f: r = client.chat.completions.create( model="openai/whisper-1", messages=[{"role":"user","content":"Transcribe the audio"}], audio={"file":f,"format":"wav"} ) return r.choices[0].message.content.strip() except: return ""