Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,14 +7,13 @@ from selenium.webdriver.chrome.options import Options
|
|
| 7 |
from selenium.webdriver.common.by import By
|
| 8 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 9 |
from selenium.webdriver.support import expected_conditions as EC
|
| 10 |
-
from selenium.common.exceptions import TimeoutException
|
| 11 |
import time
|
| 12 |
import logging
|
| 13 |
import os
|
| 14 |
import shutil
|
| 15 |
from pathlib import Path
|
| 16 |
|
| 17 |
-
|
| 18 |
app = FastAPI()
|
| 19 |
|
| 20 |
# Configure CORS
|
|
@@ -30,6 +29,7 @@ app.add_middleware(
|
|
| 30 |
logging.basicConfig(level=logging.INFO)
|
| 31 |
logger = logging.getLogger(__name__)
|
| 32 |
|
|
|
|
| 33 |
class VideoRequest(BaseModel):
|
| 34 |
url: str
|
| 35 |
|
|
@@ -39,6 +39,8 @@ class TranscriptResponse(BaseModel):
|
|
| 39 |
error: str | None
|
| 40 |
processing_time: float
|
| 41 |
|
|
|
|
|
|
|
| 42 |
def init_driver():
|
| 43 |
options = Options()
|
| 44 |
options.add_argument("--headless=new")
|
|
@@ -163,11 +165,7 @@ async def get_transcript(request: VideoRequest):
|
|
| 163 |
finally:
|
| 164 |
if driver:
|
| 165 |
driver.quit()
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
app = FastAPI()
|
| 170 |
-
|
| 171 |
@app.get("/health")
|
| 172 |
def health_check():
|
| 173 |
chrome_path = shutil.which("google-chrome")
|
|
@@ -179,11 +177,11 @@ def health_check():
|
|
| 179 |
"ChromeDriverExists": Path(chromedriver_path or "").exists()
|
| 180 |
}
|
| 181 |
|
| 182 |
-
|
| 183 |
@app.get("/")
|
| 184 |
async def root():
|
| 185 |
return {"message": "Welcome to YouTube Transcript API"}
|
| 186 |
|
| 187 |
if __name__ == "__main__":
|
| 188 |
import uvicorn
|
| 189 |
-
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))
|
|
|
|
|
|
| 7 |
from selenium.webdriver.common.by import By
|
| 8 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 9 |
from selenium.webdriver.support import expected_conditions as EC
|
| 10 |
+
from selenium.common.exceptions import TimeoutException
|
| 11 |
import time
|
| 12 |
import logging
|
| 13 |
import os
|
| 14 |
import shutil
|
| 15 |
from pathlib import Path
|
| 16 |
|
|
|
|
| 17 |
app = FastAPI()
|
| 18 |
|
| 19 |
# Configure CORS
|
|
|
|
| 29 |
logging.basicConfig(level=logging.INFO)
|
| 30 |
logger = logging.getLogger(__name__)
|
| 31 |
|
| 32 |
+
# Pydantic models
|
| 33 |
class VideoRequest(BaseModel):
|
| 34 |
url: str
|
| 35 |
|
|
|
|
| 39 |
error: str | None
|
| 40 |
processing_time: float
|
| 41 |
|
| 42 |
+
# Driver init and route handlers here...
|
| 43 |
+
|
| 44 |
def init_driver():
|
| 45 |
options = Options()
|
| 46 |
options.add_argument("--headless=new")
|
|
|
|
| 165 |
finally:
|
| 166 |
if driver:
|
| 167 |
driver.quit()
|
| 168 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
@app.get("/health")
|
| 170 |
def health_check():
|
| 171 |
chrome_path = shutil.which("google-chrome")
|
|
|
|
| 177 |
"ChromeDriverExists": Path(chromedriver_path or "").exists()
|
| 178 |
}
|
| 179 |
|
|
|
|
| 180 |
@app.get("/")
|
| 181 |
async def root():
|
| 182 |
return {"message": "Welcome to YouTube Transcript API"}
|
| 183 |
|
| 184 |
if __name__ == "__main__":
|
| 185 |
import uvicorn
|
| 186 |
+
uvicorn.run(app, host="0.0.0.0", port=int(os.getenv("PORT", 7860)))
|
| 187 |
+
|