Spaces:
Sleeping
Sleeping
Download modules/transcribe_nebius.py from Prometheu3/Behavior_Changer: direct link, hf CLI and curl.
- Browser
- Download file 828 Bytes
-
https://huggingface.co/spaces/Prometheu3/Behavior_Changer/resolve/main/modules/transcribe_nebius.py
- Command line
-
hf download hf://spaces/Prometheu3/Behavior_Changer/modules/transcribe_nebius.py
-
curl -L -o transcribe_nebius.py https://huggingface.co/spaces/Prometheu3/Behavior_Changer/resolve/main/modules/transcribe_nebius.py
828 Bytes
| 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 "" |