Spaces:
Sleeping
Sleeping
Update src/api/notes_routes.py
Browse files- src/api/notes_routes.py +8 -5
src/api/notes_routes.py
CHANGED
|
@@ -22,7 +22,9 @@ from src.transcription.whisper_transcriber import WhisperTranscriber
|
|
| 22 |
from src.summarization.note_generator import NoteGenerator
|
| 23 |
|
| 24 |
logger = setup_logger(__name__)
|
| 25 |
-
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# مخزن المهام المؤقت في الذاكرة
|
| 28 |
tasks: Dict[str, Dict] = {}
|
|
@@ -53,7 +55,7 @@ async def generate_note(
|
|
| 53 |
background_tasks: BackgroundTasks,
|
| 54 |
current_user: User = Depends(get_current_user),
|
| 55 |
):
|
| 56 |
-
"""البدء في توليد ملاحظات من فيديو يوتيوب"""
|
| 57 |
task_id = str(uuid.uuid4())
|
| 58 |
user_id = current_user.id
|
| 59 |
|
|
@@ -109,10 +111,10 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
|
|
| 109 |
except:
|
| 110 |
transcript_text = None
|
| 111 |
|
| 112 |
-
# 2. لو مفيش ترجمة، نحمل الصوت ونستخدم Whisper
|
| 113 |
if not transcript_text:
|
| 114 |
tasks[task_id]["status"] = "downloading"
|
| 115 |
-
logger.info(f"Downloading audio with POT Solver for: {video_id}")
|
| 116 |
audio_file = downloader.download_audio(youtube_url, video_id)
|
| 117 |
|
| 118 |
if not audio_file:
|
|
@@ -154,13 +156,14 @@ async def process_video_task(task_id: str, youtube_url: str, language: str, user
|
|
| 154 |
|
| 155 |
tasks[task_id]["status"] = "completed"
|
| 156 |
tasks[task_id]["notes"] = final_markdown
|
| 157 |
-
logger.info(f"✅ Task {task_id} finished!")
|
| 158 |
|
| 159 |
except Exception as e:
|
| 160 |
logger.error(f"❌ Task {task_id} failed: {e}")
|
| 161 |
tasks[task_id]["status"] = "failed"
|
| 162 |
tasks[task_id]["message"] = str(e)
|
| 163 |
finally:
|
|
|
|
| 164 |
if audio_file and downloader:
|
| 165 |
downloader.cleanup(audio_file)
|
| 166 |
|
|
|
|
| 22 |
from src.summarization.note_generator import NoteGenerator
|
| 23 |
|
| 24 |
logger = setup_logger(__name__)
|
| 25 |
+
|
| 26 |
+
# تم إزالة prefix="/notes" لضمان عمل الروابط مباشرة
|
| 27 |
+
router = APIRouter(tags=["Notes"])
|
| 28 |
|
| 29 |
# مخزن المهام المؤقت في الذاكرة
|
| 30 |
tasks: Dict[str, Dict] = {}
|
|
|
|
| 55 |
background_tasks: BackgroundTasks,
|
| 56 |
current_user: User = Depends(get_current_user),
|
| 57 |
):
|
| 58 |
+
"""البدء في توليد ملاحظات من فيديو يوتيوب مباشرة"""
|
| 59 |
task_id = str(uuid.uuid4())
|
| 60 |
user_id = current_user.id
|
| 61 |
|
|
|
|
| 111 |
except:
|
| 112 |
transcript_text = None
|
| 113 |
|
| 114 |
+
# 2. لو مفيش ترجمة، نحمل الصوت ونستخدم Whisper مع الـ POT Solver الجديد
|
| 115 |
if not transcript_text:
|
| 116 |
tasks[task_id]["status"] = "downloading"
|
| 117 |
+
logger.info(f"🚀 Downloading audio with POT Solver for: {video_id}")
|
| 118 |
audio_file = downloader.download_audio(youtube_url, video_id)
|
| 119 |
|
| 120 |
if not audio_file:
|
|
|
|
| 156 |
|
| 157 |
tasks[task_id]["status"] = "completed"
|
| 158 |
tasks[task_id]["notes"] = final_markdown
|
| 159 |
+
logger.info(f"✅ Task {task_id} finished successfully!")
|
| 160 |
|
| 161 |
except Exception as e:
|
| 162 |
logger.error(f"❌ Task {task_id} failed: {e}")
|
| 163 |
tasks[task_id]["status"] = "failed"
|
| 164 |
tasks[task_id]["message"] = str(e)
|
| 165 |
finally:
|
| 166 |
+
# تنظيف الملفات المؤقتة لتوفير مساحة السيرفر
|
| 167 |
if audio_file and downloader:
|
| 168 |
downloader.cleanup(audio_file)
|
| 169 |
|