Spaces:
Running
Running
שיפור: אפשרות להוספת קובץ וידאו
Browse files- README.md +1 -1
- main.py +3 -3
- templates/index.html +4 -4
README.md
CHANGED
|
@@ -15,7 +15,7 @@ app_port: 7860
|
|
| 15 |
### כיצד להשתמש?
|
| 16 |
|
| 17 |
1. **הזן מפתח API:** הדבק את מפתח ה-API שלך מ-Google AI Studio בתיבה המיועדת. ניתן להשיג מפתח [כאן](https://aistudio.google.com/app/apikey).
|
| 18 |
-
2. **העלה קובץ
|
| 19 |
3. **התחל תמלול:** לחץ על הכפתור "התחל תמלול" והמתן לסיום התהליך.
|
| 20 |
4. **הורד תוצאות:** לאחר סיום התמלול, תוכל לראות את התוצאה ולהוריד את קובץ ה-SRT.
|
| 21 |
|
|
|
|
| 15 |
### כיצד להשתמש?
|
| 16 |
|
| 17 |
1. **הזן מפתח API:** הדבק את מפתח ה-API שלך מ-Google AI Studio בתיבה המיועדת. ניתן להשיג מפתח [כאן](https://aistudio.google.com/app/apikey).
|
| 18 |
+
2. **העלה קובץ שמע או וידאו:** לחץ או גרור קובץ שמע או וידאו בפורמט נתמך (כגון MP3, MP4, WAV, M4A).
|
| 19 |
3. **התחל תמלול:** לחץ על הכפתור "התחל תמלול" והמתן לסיום התהליך.
|
| 20 |
4. **הורד תוצאות:** לאחר סיום התמלול, תוכל לראות את התוצאה ולהוריד את קובץ ה-SRT.
|
| 21 |
|
main.py
CHANGED
|
@@ -234,9 +234,9 @@ async def _transcribe_and_stream(api_key: str, file_content: bytes, model_name:
|
|
| 234 |
return json.dumps({"type": type, "message": message, "percent": percent, "data": data}) + "\n\n"
|
| 235 |
try:
|
| 236 |
system_prompt, pydantic_schema = load_system_prompt(), TranscriptionSegment
|
| 237 |
-
yield send_event("progress", "מעבד את קובץ
|
| 238 |
audio = AudioSegment.from_file(io.BytesIO(file_content))
|
| 239 |
-
yield send_event("progress", f"אורך
|
| 240 |
chunks = await asyncio.to_thread(split_audio_webrtcvad, audio, MIN_SILENCE_LEN_MS)
|
| 241 |
if not chunks: raise ValueError("לא נוצרו מקטעי שמע לעיבוד.")
|
| 242 |
chunk_info_messages = [f"{i+1}. {format_ms_to_srt_time(sum(len(c) for c in chunks[:i]))} - {format_ms_to_srt_time(sum(len(c) for c in chunks[:i+1]))}" for i in range(len(chunks))]
|
|
@@ -357,4 +357,4 @@ async def handle_transcription_stream(api_key: str = Form(...), model_name: str
|
|
| 357 |
if not all([api_key, model_name, audio_file]):
|
| 358 |
raise HTTPException(status_code=400, detail="Required form fields are missing.")
|
| 359 |
file_content = await audio_file.read()
|
| 360 |
-
return StreamingResponse(_transcribe_and_stream(api_key, file_content, model_name, user_prompt), media_type="text/event-stream")
|
|
|
|
| 234 |
return json.dumps({"type": type, "message": message, "percent": percent, "data": data}) + "\n\n"
|
| 235 |
try:
|
| 236 |
system_prompt, pydantic_schema = load_system_prompt(), TranscriptionSegment
|
| 237 |
+
yield send_event("progress", "מעבד את קובץ המדיה...", 5)
|
| 238 |
audio = AudioSegment.from_file(io.BytesIO(file_content))
|
| 239 |
+
yield send_event("progress", f"אורך פס הקול {len(audio) / 60000:.1f} דקות. מבצע חלוקה...", 15)
|
| 240 |
chunks = await asyncio.to_thread(split_audio_webrtcvad, audio, MIN_SILENCE_LEN_MS)
|
| 241 |
if not chunks: raise ValueError("לא נוצרו מקטעי שמע לעיבוד.")
|
| 242 |
chunk_info_messages = [f"{i+1}. {format_ms_to_srt_time(sum(len(c) for c in chunks[:i]))} - {format_ms_to_srt_time(sum(len(c) for c in chunks[:i+1]))}" for i in range(len(chunks))]
|
|
|
|
| 357 |
if not all([api_key, model_name, audio_file]):
|
| 358 |
raise HTTPException(status_code=400, detail="Required form fields are missing.")
|
| 359 |
file_content = await audio_file.read()
|
| 360 |
+
return StreamingResponse(_transcribe_and_stream(api_key, file_content, model_name, user_prompt), media_type="text/event-stream")
|
templates/index.html
CHANGED
|
@@ -113,13 +113,13 @@
|
|
| 113 |
</div>
|
| 114 |
|
| 115 |
<div class="input-group">
|
| 116 |
-
<label for="audio-file-input">קובץ שמע (mp3, wav, m4a, etc.)</label>
|
| 117 |
<label for="audio-file-input" class="file-input-wrapper" id="audio-drop-zone">
|
| 118 |
<span class="material-symbols-outlined">upload_file</span>
|
| 119 |
<p>לחץ לבחירת קובץ או גרור לכאן</p>
|
| 120 |
<div id="audio-file-name" class="file-name"></div>
|
| 121 |
</label>
|
| 122 |
-
<input type="file" id="audio-file-input" accept="audio/*" required>
|
| 123 |
</div>
|
| 124 |
|
| 125 |
<div class="buttons-container" style="margin-top: 2rem; flex-wrap: wrap; justify-content: center;">
|
|
@@ -271,13 +271,13 @@
|
|
| 271 |
if (audioFileInput.disabled) return;
|
| 272 |
audioDropZone.classList.remove('drag-over');
|
| 273 |
const droppedFile = e.dataTransfer.files[0];
|
| 274 |
-
if (droppedFile && droppedFile.type.startsWith('audio/')) {
|
| 275 |
audioFile = droppedFile;
|
| 276 |
audioFileInput.files = e.dataTransfer.files;
|
| 277 |
audioFileNameEl.textContent = `קובץ: ${audioFile.name}`;
|
| 278 |
} else {
|
| 279 |
audioFile = null;
|
| 280 |
-
audioFileNameEl.textContent = 'יש לבחור קובץ שמע
|
| 281 |
}
|
| 282 |
checkInputs();
|
| 283 |
});
|
|
|
|
| 113 |
</div>
|
| 114 |
|
| 115 |
<div class="input-group">
|
| 116 |
+
<label for="audio-file-input">קובץ שמע או וידאו (mp3, mp4, wav, m4a, etc.)</label>
|
| 117 |
<label for="audio-file-input" class="file-input-wrapper" id="audio-drop-zone">
|
| 118 |
<span class="material-symbols-outlined">upload_file</span>
|
| 119 |
<p>לחץ לבחירת קובץ או גרור לכאן</p>
|
| 120 |
<div id="audio-file-name" class="file-name"></div>
|
| 121 |
</label>
|
| 122 |
+
<input type="file" id="audio-file-input" accept="audio/*,video/*" required>
|
| 123 |
</div>
|
| 124 |
|
| 125 |
<div class="buttons-container" style="margin-top: 2rem; flex-wrap: wrap; justify-content: center;">
|
|
|
|
| 271 |
if (audioFileInput.disabled) return;
|
| 272 |
audioDropZone.classList.remove('drag-over');
|
| 273 |
const droppedFile = e.dataTransfer.files[0];
|
| 274 |
+
if (droppedFile && (droppedFile.type.startsWith('audio/') || droppedFile.type.startsWith('video/'))) {
|
| 275 |
audioFile = droppedFile;
|
| 276 |
audioFileInput.files = e.dataTransfer.files;
|
| 277 |
audioFileNameEl.textContent = `קובץ: ${audioFile.name}`;
|
| 278 |
} else {
|
| 279 |
audioFile = null;
|
| 280 |
+
audioFileNameEl.textContent = 'יש לבחור קובץ שמע או וידאו';
|
| 281 |
}
|
| 282 |
checkInputs();
|
| 283 |
});
|