Download app/api.py from minhvh/her: direct link, hf CLI and curl.
- Browser
- Download file 2.27 kB
-
https://huggingface.co/spaces/minhvh/her/resolve/main/app/api.py
- Command line
-
hf download hf://spaces/minhvh/her/app/api.py
-
curl -L -o api.py https://huggingface.co/spaces/minhvh/her/resolve/main/app/api.py
2.27 kB
| """Cloud Browser API V2 - RESTful feature-based structure.""" | |
| import asyncio | |
| import importlib | |
| import inspect | |
| import logging | |
| import os | |
| import pkgutil | |
| import sys | |
| import traceback | |
| from contextlib import asynccontextmanager | |
| from typing import List, Dict, Any, Optional | |
| from fastapi import Depends, FastAPI, WebSocket, APIRouter | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.openapi.docs import get_swagger_ui_html | |
| from fastapi.openapi.utils import get_openapi | |
| from fastapi.responses import HTMLResponse | |
| # Set up logging properly | |
| logging.basicConfig(level=logging.INFO) | |
| logger = logging.getLogger(__name__) | |
| async def lifespan(app: FastAPI): | |
| """Application lifecycle manager.""" | |
| logger.info("Starting Cloud") | |
| yield | |
| logger.info("Cloud shutdown") | |
| # Create FastAPI application | |
| app = FastAPI( | |
| title="Cloud Browser API", | |
| description=""" | |
| # Cloud Browser API Documentation | |
| API này cung cấp các endpoint để quản lý và điều khiển các trình duyệt ảo trên đám mây. | |
| Bạn có thể tạo, quản lý và tương tác với các phiên trình duyệt thông qua API này. | |
| ## Tính năng chính | |
| * Tạo và quản lý các phiên trình duyệt | |
| * Điều khiển trình duyệt qua WebSocket | |
| * Thực hiện các tác vụ tự động hóa | |
| * Quản lý tiện ích mở rộng trình duyệt | |
| ## Authentication | |
| API này sử dụng token-based authentication. Vui lòng liên hệ với quản trị viên để được cấp token. | |
| """, | |
| version="2.0.0", | |
| lifespan=lifespan, | |
| docs_url="/docs", # URL cho Swagger UI | |
| openapi_url="/openapi.json", # URL để lấy schema OpenAPI | |
| contact={ | |
| "name": "API Support", | |
| "url": "http://example.com/support", | |
| "email": "support@example.com", | |
| }, | |
| license_info={ | |
| "name": "Proprietary", | |
| "url": "http://example.com/license", | |
| }, | |
| ) | |
| # Add CORS middleware | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| def api_status(): | |
| """Check API status.""" | |
| return {"status": "ok", "version": "2.0.0"} | |