Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -2,29 +2,10 @@ import gradio as gr
|
|
| 2 |
import base64
|
| 3 |
import torch
|
| 4 |
from transformers import pipeline
|
| 5 |
-
import io
|
| 6 |
-
import os
|
| 7 |
-
import tempfile
|
| 8 |
-
from moviepy import VideoFileClip
|
| 9 |
|
| 10 |
# Whisper ๋ชจ๋ธ์ pipeline์ผ๋ก ๋ถ๋ฌ์ค๊ธฐ
|
| 11 |
whisper = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 12 |
|
| 13 |
-
def extract_audio(video_path):
|
| 14 |
-
try:
|
| 15 |
-
# ์์ ํ์ผ ์์ฑ
|
| 16 |
-
temp_audio_path = tempfile.NamedTemporaryFile(suffix='.mp3', delete=False).name
|
| 17 |
-
|
| 18 |
-
# ๋น๋์ค ํ์ผ ๋ก๋
|
| 19 |
-
video = VideoFileClip(video_path)
|
| 20 |
-
|
| 21 |
-
# ์ค๋์ค ์ถ์ถ ๋ฐ ์์ ํ์ผ๋ก ์ ์ฅ
|
| 22 |
-
video.audio.write_audiofile(temp_audio_path, codec='mp3', verbose=False, logger=None)
|
| 23 |
-
|
| 24 |
-
return temp_audio_path
|
| 25 |
-
except Exception as e:
|
| 26 |
-
return f"์ค๋ฅ ๋ฐ์: {e}"
|
| 27 |
-
|
| 28 |
# ์์ฑ์ ํ
์คํธ๋ก ๋ณํํ๋ ํจ์
|
| 29 |
def transcribe_audio(audio):
|
| 30 |
if audio is None:
|
|
@@ -43,15 +24,7 @@ demo1 = gr.Interface(
|
|
| 43 |
submit_btn='์คํ',
|
| 44 |
clear_btn='์ง์ฐ๊ธฐ')
|
| 45 |
|
| 46 |
-
|
| 47 |
-
fn=extract_audio,
|
| 48 |
-
inputs=gr.File(label='๋น๋์ค ํ์ผ'),
|
| 49 |
-
outputs=gr.Audio(label='์ถ์ถ๋ ์ค๋์ค'),
|
| 50 |
-
title='์ด์ฐ์ง์ ์ค๋์ค ์ถ์ถ๊ธฐ',
|
| 51 |
-
submit_btn='์คํ',
|
| 52 |
-
clear_btn='์ง์ฐ๊ธฐ')
|
| 53 |
-
|
| 54 |
-
demo = gr.TabbedInterface((demo1, demo2), ('Speech-To-Text', '์ค๋์ค ์ถ์ถ๊ธฐ'))
|
| 55 |
|
| 56 |
# ์ฑ ์คํ
|
| 57 |
demo.launch()
|
|
|
|
| 2 |
import base64
|
| 3 |
import torch
|
| 4 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Whisper ๋ชจ๋ธ์ pipeline์ผ๋ก ๋ถ๋ฌ์ค๊ธฐ
|
| 7 |
whisper = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
# ์์ฑ์ ํ
์คํธ๋ก ๋ณํํ๋ ํจ์
|
| 10 |
def transcribe_audio(audio):
|
| 11 |
if audio is None:
|
|
|
|
| 24 |
submit_btn='์คํ',
|
| 25 |
clear_btn='์ง์ฐ๊ธฐ')
|
| 26 |
|
| 27 |
+
demo = gr.TabbedInterface((demo1), ('Speech-To-Text'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# ์ฑ ์คํ
|
| 30 |
demo.launch()
|