Spaces:
Sleeping
Sleeping
import gradio as gr | |
from faster_whisper import WhisperModel | |
from pydub import AudioSegment | |
import os | |
import tempfile | |
from transformers import pipeline | |
# ืืืืจืช ืืืืื ืืชืืืื | |
model = WhisperModel("ivrit-ai/faster-whisper-v2-d4") | |
# ืืืืจืช pipeline ืืกืืืื | |
summarizer = pipeline("summarization", model="facebook/bart-large-cnn") | |
def summarize_audio_or_video(file_path): | |
try: | |
# ืืืืงื ืื ืืงืืืฅ ืืื ืืืืื ืืืืจืช ืืืืื ืืืืืื ืืืืืช ืืฆืืจื | |
if file_path.endswith((".mp4", ".mov", ".avi", ".mkv")): | |
audio_file = convert_video_to_audio(file_path) | |
else: | |
audio_file = file_path | |
# ืชืืืื ืืืืืื | |
segments, _ = model.transcribe(audio_file, language="he") | |
transcript = " ".join([segment.text for segment in segments]) | |
# ืกืืืื ืืชืืืื | |
summary = summarizer(transcript, max_length=50, min_length=25, do_sample=False)[0]["summary_text"] | |
# ืืืืงืช ืงืืืฅ ืืืืืื ืืืืืช ืืฆืืจื (ืื ืืื ืืืืื) | |
if audio_file != file_path: | |
os.remove(audio_file) | |
return summary | |
except Exception as e: | |
return f"ืฉืืืื ืืขืืืื ืืงืืืฅ: {str(e)}" | |
def convert_video_to_audio(video_file): | |
# ืืฆืืจืช ืงืืืฅ ืืืืื ืืื ื | |
temp_audio = tempfile.mktemp(suffix=".wav") | |
video = AudioSegment.from_file(video_file) | |
video.export(temp_audio, format="wav") | |
return temp_audio | |
# ืืืืจืช ืืืฉืง Gradio | |
interface = gr.Interface( | |
fn=summarize_audio_or_video, | |
inputs=gr.Audio(type="filepath"), | |
outputs="text", | |
title="ืืืืจ ืืืืื/ืืืืื ืืกืืืื", | |
description="ืืขืื ืงืืืฅ ืืืืื ืื ืืืืื ืฉื ืืจืฆื ืืงืื ืกืืืื ืงืฆืจ ืฉื ืืชืืื." | |
) | |
if __name__ == "__main__": | |
interface.launch() | |