Neo2902 commited on
Commit ·
0549d36
1
Parent(s): 5d5a3ff
Projet complet avec chunking, extract_playlist et youtube_search
Browse files
app.py
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
from fastapi.responses import JSONResponse
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI()
|
| 6 |
|
|
@@ -21,7 +35,7 @@ app.add_middleware(
|
|
| 21 |
|
| 22 |
@app.get("/")
|
| 23 |
async def root():
|
| 24 |
-
return {"message": "API HF space
|
| 25 |
|
| 26 |
@app.post("/extract")
|
| 27 |
async def extract(request: Request):
|
|
@@ -29,10 +43,9 @@ async def extract(request: Request):
|
|
| 29 |
playlist_url = data.get("playlistUrl")
|
| 30 |
if not playlist_url:
|
| 31 |
return JSONResponse(status_code=400, content={"message": "Playlist URL manquante"})
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
"playlist":
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
}
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
|
| 5 |
+
# Installer Playwright au démarrage (avant imports FastAPI)
|
| 6 |
+
subprocess.run(["playwright", "install"], check=True)
|
| 7 |
+
|
| 8 |
+
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
|
| 9 |
+
|
| 10 |
+
import chunking
|
| 11 |
+
import extract_playlist_playwright
|
| 12 |
+
import youtube_search
|
| 13 |
+
|
| 14 |
from fastapi import FastAPI, Request
|
| 15 |
from fastapi.middleware.cors import CORSMiddleware
|
| 16 |
from fastapi.responses import JSONResponse
|
| 17 |
+
import asyncio
|
| 18 |
|
| 19 |
app = FastAPI()
|
| 20 |
|
|
|
|
| 35 |
|
| 36 |
@app.get("/")
|
| 37 |
async def root():
|
| 38 |
+
return {"message": "API HF space prête"}
|
| 39 |
|
| 40 |
@app.post("/extract")
|
| 41 |
async def extract(request: Request):
|
|
|
|
| 43 |
playlist_url = data.get("playlistUrl")
|
| 44 |
if not playlist_url:
|
| 45 |
return JSONResponse(status_code=400, content={"message": "Playlist URL manquante"})
|
| 46 |
+
|
| 47 |
+
try:
|
| 48 |
+
songs = await extract_playlist_playwright.extract_playlist(playlist_url) # Extraction liste morceaux
|
| 49 |
+
return {"message": f"{len(songs)} morceaux extraits.", "playlist": songs}
|
| 50 |
+
except Exception as e:
|
| 51 |
+
return JSONResponse(status_code=500, content={"message": f"Erreur extraction : {str(e)}"})
|
|
|