Spaces:
Sleeping
Sleeping
serve on hf app page
Browse files- backend/main.py +20 -2
backend/main.py
CHANGED
|
@@ -7,16 +7,30 @@ import os
|
|
| 7 |
import httpx
|
| 8 |
from fastapi import FastAPI, Header, HTTPException
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 10 |
from scalar_fastapi import get_scalar_api_reference
|
| 11 |
from pydantic import BaseModel, Field
|
| 12 |
|
| 13 |
import providers
|
| 14 |
from languages import as_list
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
app = FastAPI(
|
| 17 |
title="Translator Model API",
|
| 18 |
-
description=
|
| 19 |
-
version="
|
| 20 |
)
|
| 21 |
|
| 22 |
_origins = os.environ.get("CORS_ORIGINS", "*").split(",")
|
|
@@ -123,3 +137,7 @@ async def scalar_html():
|
|
| 123 |
openapi_url=app.openapi_url,
|
| 124 |
title=app.title,
|
| 125 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
import httpx
|
| 8 |
from fastapi import FastAPI, Header, HTTPException
|
| 9 |
from fastapi.middleware.cors import CORSMiddleware
|
| 10 |
+
from fastapi.responses import RedirectResponse
|
| 11 |
from scalar_fastapi import get_scalar_api_reference
|
| 12 |
from pydantic import BaseModel, Field
|
| 13 |
|
| 14 |
import providers
|
| 15 |
from languages import as_list
|
| 16 |
|
| 17 |
+
readme_path = os.path.join(os.path.dirname(__file__), "..", "README.md")
|
| 18 |
+
readme_content = ""
|
| 19 |
+
|
| 20 |
+
if os.path.exists(readme_path):
|
| 21 |
+
with open(readme_path, "r", encoding="utf-8") as f:
|
| 22 |
+
raw_text = f.read()
|
| 23 |
+
|
| 24 |
+
if raw_text.startswith("---"):
|
| 25 |
+
parts = raw_text.split("---", 2)
|
| 26 |
+
readme_content = parts[2] if len(parts) >= 3 else raw_text
|
| 27 |
+
else:
|
| 28 |
+
readme_content = raw_text
|
| 29 |
+
|
| 30 |
app = FastAPI(
|
| 31 |
title="Translator Model API",
|
| 32 |
+
description=readme_content,
|
| 33 |
+
version="1.3.0",
|
| 34 |
)
|
| 35 |
|
| 36 |
_origins = os.environ.get("CORS_ORIGINS", "*").split(",")
|
|
|
|
| 137 |
openapi_url=app.openapi_url,
|
| 138 |
title=app.title,
|
| 139 |
)
|
| 140 |
+
|
| 141 |
+
@app.get("/", include_in_schema=False)
|
| 142 |
+
def root():
|
| 143 |
+
return RedirectResponse(url="/scalar")
|