Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,50 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# ืืฆืืจืช
|
| 5 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 6 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# ืืืืจืช ืืืฉืง Gradio
|
| 16 |
interface = gr.Interface(
|
| 17 |
-
fn=
|
| 18 |
-
inputs=gr.Audio(type="filepath"), #
|
| 19 |
outputs="text",
|
| 20 |
-
title="ืืืืจ
|
| 21 |
-
description="ืืขืื ืงืืืฅ ืืืืื ืฉื ืืจืฆื ืืงืื ืกืืืื ืงืฆืจ ืฉื ืืชืืื."
|
| 22 |
)
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
+
from pydub import AudioSegment
|
| 4 |
+
import os
|
| 5 |
+
import tempfile
|
| 6 |
|
| 7 |
+
# ืืฆืืจืช pipeline ืืชืืืื ืืืกืืืื
|
| 8 |
transcriber = pipeline("automatic-speech-recognition", model="openai/whisper-base")
|
| 9 |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 10 |
|
| 11 |
+
def summarize_audio_or_video(file_path):
|
| 12 |
+
try:
|
| 13 |
+
# ืืืืงื ืื ืืงืืืฅ ืืื ืืืืื ืืืืจืช ืืืืื ืืืืืื ืืืืืช ืืฆืืจื
|
| 14 |
+
if file_path.endswith((".mp4", ".mov", ".avi", ".mkv")):
|
| 15 |
+
audio_file = convert_video_to_audio(file_path)
|
| 16 |
+
else:
|
| 17 |
+
audio_file = file_path
|
| 18 |
+
|
| 19 |
+
# ืชืืืื ืืืืืื
|
| 20 |
+
transcript = transcriber(audio_file)["text"]
|
| 21 |
+
|
| 22 |
+
# ืืฆืืจืช ืกืืืื ืฉื ืืชืืืื
|
| 23 |
+
summary = summarizer(transcript, max_length=50, min_length=25, do_sample=False)[0]["summary_text"]
|
| 24 |
+
|
| 25 |
+
# ืืืืงืช ืงืืืฅ ืืืืืื ืืืืืช ืืฆืืจื (ืื ืืื ืืืืื)
|
| 26 |
+
if audio_file != file_path:
|
| 27 |
+
os.remove(audio_file)
|
| 28 |
+
|
| 29 |
+
return summary
|
| 30 |
+
|
| 31 |
+
except Exception as e:
|
| 32 |
+
return f"ืฉืืืื ืืขืืืื ืืงืืืฅ: {str(e)}"
|
| 33 |
+
|
| 34 |
+
def convert_video_to_audio(video_file):
|
| 35 |
+
# ืืฆืืจืช ืงืืืฅ ืืืืื ืืื ื
|
| 36 |
+
temp_audio = tempfile.mktemp(suffix=".wav")
|
| 37 |
+
video = AudioSegment.from_file(video_file)
|
| 38 |
+
video.export(temp_audio, format="wav")
|
| 39 |
+
return temp_audio
|
| 40 |
|
| 41 |
# ืืืืจืช ืืืฉืง Gradio
|
| 42 |
interface = gr.Interface(
|
| 43 |
+
fn=summarize_audio_or_video,
|
| 44 |
+
inputs=gr.Audio(type="filepath"), # ืืชืืื ืืืืืื ืืืืืื
|
| 45 |
outputs="text",
|
| 46 |
+
title="ืืืืจ ืืืืื/ืืืืื ืืกืืืื",
|
| 47 |
+
description="ืืขืื ืงืืืฅ ืืืืื ืื ืืืืื ืฉื ืืจืฆื ืืงืื ืกืืืื ืงืฆืจ ืฉื ืืชืืื."
|
| 48 |
)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|