Spaces:
Sleeping
Sleeping
Update pipelines/ai_inference.py
Browse files- pipelines/ai_inference.py +23 -0
pipelines/ai_inference.py
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import openai
|
| 2 |
+
import whisper
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
def transcribe_audio(audio_file):
|
| 6 |
+
# Option A: local Whisper
|
| 7 |
+
model = whisper.load_model("base")
|
| 8 |
+
result = model.transcribe(audio_file)
|
| 9 |
+
return result["text"]
|
| 10 |
+
|
| 11 |
+
def generate_edit_instructions(transcript_text):
|
| 12 |
+
system_msg = """You are a video editing assistant..."""
|
| 13 |
+
user_msg = f"Transcript:\n{transcript_text}\n\nOutput instructions in JSON..."
|
| 14 |
+
|
| 15 |
+
# GPT-based approach
|
| 16 |
+
response = openai.ChatCompletion.create(
|
| 17 |
+
model="gpt-4",
|
| 18 |
+
messages=[
|
| 19 |
+
{"role": "system", "content": system_msg},
|
| 20 |
+
{"role": "user", "content": user_msg}
|
| 21 |
+
],
|
| 22 |
+
)
|
| 23 |
+
return response.choices[0].message["content"]
|