Spaces:
Runtime error
Runtime error
File size: 1,319 Bytes
592221d 9140841 5d24462 9140841 592221d 77ccdf4 592221d 9140841 592221d 9140841 592221d |
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 |
import json
import ffmpeg
from subprocess import run
import gradio as gr
import uuid
import os
import stat
from zipfile import ZipFile
import whisper_timestamped as whisper
from transformers import pipeline
model = whisper.load_model("small", device="cpu")
sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions", use_fast=True)
ZipFile("ffmpeg.zip").extractall()
st = os.stat('ffmpeg')
os.chmod('ffmpeg', st.st_mode | stat.S_IEXEC)
print("cwd", os.getcwd())
print(os.listdir())
def analyze_sentiment(text):
results = sentiment_analysis(text)
sentiment_results = {result['label']: result['score'] for result in results}
return sentiment_results
def transcribe(audio):
audio = whisper.load_audio(audio)
result = whisper.transcribe(model, audio)
print(json.dumps(result, indent=2, ensure_ascii=False))
sent_res = analyze_sentiment(result.text)
return sent_res
def video_to_audio(input_video, output_audio):
current_path = os.getcwd()
common_uuid = uuid.uuid4()
audio_file = f"{common_uuid}.wav"
run(["ffmpeg", "-i", 'test_video_1.mp4', audio_file])
response = transcribe(audio=audio_file)
return response
gr.Interface(
fn=video_to_audio,
inputs=gr.Video(),
outputs=gr.Textbox()
).launch() |