Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,8 @@ import os
|
|
2 |
import uvicorn
|
3 |
from fastapi import FastAPI, HTTPException
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
-
from fastapi.responses import HTMLResponse
|
|
|
6 |
from pydantic import BaseModel
|
7 |
from transformers import pipeline, AutoTokenizer, AutoModel, set_seed
|
8 |
import torch
|
@@ -25,6 +26,12 @@ app.add_middleware(
|
|
25 |
allow_headers=["*"],
|
26 |
)
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
# Set seed untuk konsistensi
|
29 |
set_seed(42)
|
30 |
|
@@ -491,23 +498,6 @@ async def inference(request: dict):
|
|
491 |
"status": "error"
|
492 |
}
|
493 |
|
494 |
-
# Simple root endpoint
|
495 |
-
@app.get("/")
|
496 |
-
async def root():
|
497 |
-
return {
|
498 |
-
"message": "Character AI Backend Ready",
|
499 |
-
"version": "1.0.0",
|
500 |
-
"platform": "CPU Optimized",
|
501 |
-
"endpoints": {
|
502 |
-
"chat": "/chat",
|
503 |
-
"models": "/models",
|
504 |
-
"health": "/health",
|
505 |
-
"config": "/config",
|
506 |
-
"inference": "/inference"
|
507 |
-
},
|
508 |
-
"frontend": "Serve index.html separately"
|
509 |
-
}
|
510 |
-
|
511 |
# Run dengan CPU optimizations
|
512 |
if __name__ == "__main__":
|
513 |
port = int(os.environ.get("PORT", 7860))
|
@@ -515,6 +505,7 @@ if __name__ == "__main__":
|
|
515 |
app,
|
516 |
host="0.0.0.0",
|
517 |
port=port,
|
|
|
518 |
workers=1,
|
519 |
timeout_keep_alive=30,
|
520 |
access_log=False
|
|
|
2 |
import uvicorn
|
3 |
from fastapi import FastAPI, HTTPException
|
4 |
from fastapi.middleware.cors import CORSMiddleware
|
5 |
+
from fastapi.responses import HTMLResponse, FileResponse
|
6 |
+
from fastapi.staticfiles import StaticFiles
|
7 |
from pydantic import BaseModel
|
8 |
from transformers import pipeline, AutoTokenizer, AutoModel, set_seed
|
9 |
import torch
|
|
|
26 |
allow_headers=["*"],
|
27 |
)
|
28 |
|
29 |
+
@app.get("/", response_class=HTMLResponse)
|
30 |
+
async def serve_frontend():
|
31 |
+
return FileResponse("index.html")
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
# Set seed untuk konsistensi
|
36 |
set_seed(42)
|
37 |
|
|
|
498 |
"status": "error"
|
499 |
}
|
500 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
501 |
# Run dengan CPU optimizations
|
502 |
if __name__ == "__main__":
|
503 |
port = int(os.environ.get("PORT", 7860))
|
|
|
505 |
app,
|
506 |
host="0.0.0.0",
|
507 |
port=port,
|
508 |
+
log_level="info",
|
509 |
workers=1,
|
510 |
timeout_keep_alive=30,
|
511 |
access_log=False
|