fix(lyric_translator): add readme and add async request
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import os
|
||||
import re
|
||||
import asyncio
|
||||
from app.core.deepseek_client import chat_with_openai
|
||||
from app.models.lyric_romanji_translator import FileResult
|
||||
|
||||
semaphore = asyncio.Semaphore(5)
|
||||
timestamp_pattern = re.compile(r"^\[\d{2}:\d{2}\.\d{2}\]")
|
||||
|
||||
def needs_romaji(lines, idx):
|
||||
@@ -39,21 +41,28 @@ async def process_lrc_file(filepath: str) -> FileResult:
|
||||
|
||||
return FileResult(file=filepath, processed=added_lines > 0, added_lines=added_lines)
|
||||
|
||||
async def safe_process(filepath):
|
||||
async with semaphore:
|
||||
print(f"Processing: {filepath}")
|
||||
return await process_lrc_file(filepath)
|
||||
|
||||
async def translate_lyric_romanji(folder_path: str):
|
||||
results = []
|
||||
|
||||
if not os.path.exists(folder_path):
|
||||
return {"results": [], "status": f"error: folder not found {folder_path}"}
|
||||
|
||||
tasks = []
|
||||
for root, _, files in os.walk(folder_path):
|
||||
for file in files:
|
||||
if file.endswith(".lrc"):
|
||||
filepath = os.path.join(root, file)
|
||||
print(f"Processing: {filepath}")
|
||||
tasks.append(asyncio.create_task(safe_process(filepath)))
|
||||
|
||||
result = await process_lrc_file(filepath)
|
||||
if not tasks:
|
||||
return {"results": [], "status": "no .lrc files found"}
|
||||
|
||||
# ✅ result is already a FileResult object
|
||||
results.append(result)
|
||||
# Run them all concurrently
|
||||
results = await asyncio.gather(*tasks)
|
||||
|
||||
return {"results": results, "status": "completed"}
|
||||
31
readme.md
31
readme.md
@@ -0,0 +1,31 @@
|
||||
|
||||
# Project Title
|
||||
|
||||
A brief description of what this project does and who it's for
|
||||
|
||||
|
||||
## Run Locally
|
||||
|
||||
Clone the project
|
||||
|
||||
```bash
|
||||
git clone https://link-to-project
|
||||
```
|
||||
|
||||
Go to the project directory
|
||||
|
||||
```bash
|
||||
cd my-project
|
||||
```
|
||||
|
||||
Install dependencies
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
Start the server
|
||||
|
||||
```bash
|
||||
uvicorn app.main:app --reload
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user