Przemyslaw Chachaj commited on
Commit
199032a
·
1 Parent(s): e658037

Added Nebius transcription + AI step generation

Browse files
modules/generate_plan.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from openai import OpenAI
2
+ import os
3
+
4
+ client = OpenAI(
5
+ base_url="https://api.studio.nebius.ai/v1/",
6
+ api_key=os.environ["NEBIUS_API_KEY"]
7
+ )
8
+
9
+ def steps_from_transcript(txt:str,category:str)->list[str]:
10
+ prompt = f"""
11
+ Użytkownik oglądał materiał video.
12
+ Na podstawie transkrypcji wygeneruj **7 mikro kroków** prowadzących do działania.
13
+ Krótko. Zero lania wody.
14
+
15
+ Kategoriа: {category}
16
+
17
+ Transkrypcja (fragment):
18
+ {txt[:2000]}
19
+ """
20
+
21
+ out = client.chat.completions.create(
22
+ model="moonshotai/Kimi-K2-Instruct",
23
+ messages=[{"role":"user","content":prompt}],
24
+ max_tokens=450
25
+ ).choices[0].message.content.split("\n")
26
+
27
+ # czyścimy listę i skracamy do 7
28
+ steps=[s.strip("-• ") for s in out if len(s.strip())>10][:7]
29
+ return steps
modules/transcribe_nebius.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import yt_dlp
3
+ from openai import OpenAI
4
+
5
+ client = OpenAI(
6
+ base_url="https://api.studio.nebius.ai/v1/",
7
+ api_key=os.environ.get("NEBIUS_API_KEY")
8
+ )
9
+
10
+ def transcribe_from_url(link:str) -> str:
11
+ tmp = "/tmp/reel_audio.m4a"
12
+
13
+ ydl_opts = {
14
+ "format": "m4a/bestaudio/best",
15
+ "outtmpl": tmp,
16
+ "quiet": True,
17
+ }
18
+
19
+ try:
20
+ yt_dlp.YoutubeDL(ydl_opts).download([link])
21
+ except Exception:
22
+ return ""
23
+
24
+ # Nebius ASR
25
+ try:
26
+ with open(tmp, "rb") as f:
27
+ r = client.chat.completions.create(
28
+ model="openai/whisper-1",
29
+ messages=[{"role":"user","content":"Transcribe the audio"}],
30
+ audio={"file":f,"format":"wav"}
31
+ )
32
+ return r.choices[0].message.content.strip()
33
+ except:
34
+ return ""