Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import ffmpeg
|
| 3 |
+
from subprocess import run
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import whisper_timestamped as whisper
|
| 6 |
+
from transformers import pipeline
|
| 7 |
+
|
| 8 |
+
model = whisper.load_model("model/small.pt", device="cpu")
|
| 9 |
+
sentiment_analysis = pipeline("sentiment-analysis", framework="pt", model="SamLowe/roberta-base-go_emotions", use_fast=True)
|
| 10 |
+
|
| 11 |
+
def analyze_sentiment(text):
|
| 12 |
+
results = sentiment_analysis(text)
|
| 13 |
+
sentiment_results = {result['label']: result['score'] for result in results}
|
| 14 |
+
return sentiment_results
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def transcribe(audio):
|
| 18 |
+
audio = whisper.load_audio(audio)
|
| 19 |
+
result = whisper.transcribe(model, audio)
|
| 20 |
+
print(json.dumps(result, indent=2, ensure_ascii=False))
|
| 21 |
+
sent_res = analyze_sentiment(result.text)
|
| 22 |
+
|
| 23 |
+
return sent_res
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def video_to_audio(input_video, output_audio):
|
| 27 |
+
audio_file = f"test.wav"
|
| 28 |
+
run(["ffmpeg", "-i", 'test_video_1.mp4', audio_file])
|
| 29 |
+
|
| 30 |
+
response = transcribe(audio=audio_file)
|
| 31 |
+
|
| 32 |
+
return response
|
| 33 |
+
|
| 34 |
+
gr.Interface(
|
| 35 |
+
fn=video_to_audio,
|
| 36 |
+
inputs=gr.Video(),
|
| 37 |
+
outputs=gr.Textbox()
|
| 38 |
+
).launch()
|