Spaces:
Sleeping
Sleeping
sanbo
commited on
Commit
·
ef67bd3
1
Parent(s):
dafd397
update sth. at 2025-03-03 19:46:42
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import torch
|
|
| 5 |
import gradio as gr
|
| 6 |
from fastapi import FastAPI, HTTPException
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
| 8 |
from pydantic import BaseModel, Field, model_validator
|
| 9 |
from typing import List, Dict, Optional
|
| 10 |
|
|
@@ -105,6 +106,8 @@ app.add_middleware(
|
|
| 105 |
allow_methods=["*"],
|
| 106 |
allow_headers=["*"],
|
| 107 |
)
|
|
|
|
|
|
|
| 108 |
@app.post("/embed", response_model=EmbeddingResponse)
|
| 109 |
@app.post("/api/embeddings", response_model=EmbeddingResponse)
|
| 110 |
@app.post("/api/embed", response_model=EmbeddingResponse)
|
|
@@ -114,7 +117,7 @@ app.add_middleware(
|
|
| 114 |
@app.post("/hf/v1/embeddings", response_model=EmbeddingResponse)
|
| 115 |
@app.post("/api/v1/chat/completions", response_model=EmbeddingResponse)
|
| 116 |
@app.post("/hf/v1/chat/completions", response_model=EmbeddingResponse)
|
| 117 |
-
async def generate_embeddings(request: EmbeddingRequest):
|
| 118 |
try:
|
| 119 |
# 计算token数量
|
| 120 |
token_count = len(embedding_service.tokenizer.encode(request.inputs))
|
|
@@ -183,4 +186,4 @@ async def startup_event():
|
|
| 183 |
if __name__ == "__main__":
|
| 184 |
asyncio.run(embedding_service.initialize())
|
| 185 |
gr.mount_gradio_app(app, iface, path="/ui")
|
| 186 |
-
uvicorn.run(app, host="0.0.0.0", port=7860
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
from fastapi import FastAPI, HTTPException
|
| 7 |
from fastapi.middleware.cors import CORSMiddleware
|
| 8 |
+
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
| 9 |
from pydantic import BaseModel, Field, model_validator
|
| 10 |
from typing import List, Dict, Optional
|
| 11 |
|
|
|
|
| 106 |
allow_methods=["*"],
|
| 107 |
allow_headers=["*"],
|
| 108 |
)
|
| 109 |
+
security = HTTPBearer()
|
| 110 |
+
|
| 111 |
@app.post("/embed", response_model=EmbeddingResponse)
|
| 112 |
@app.post("/api/embeddings", response_model=EmbeddingResponse)
|
| 113 |
@app.post("/api/embed", response_model=EmbeddingResponse)
|
|
|
|
| 117 |
@app.post("/hf/v1/embeddings", response_model=EmbeddingResponse)
|
| 118 |
@app.post("/api/v1/chat/completions", response_model=EmbeddingResponse)
|
| 119 |
@app.post("/hf/v1/chat/completions", response_model=EmbeddingResponse)
|
| 120 |
+
async def generate_embeddings(request: EmbeddingRequest, credentials: HTTPAuthorizationCredentials = Depends(security)):
|
| 121 |
try:
|
| 122 |
# 计算token数量
|
| 123 |
token_count = len(embedding_service.tokenizer.encode(request.inputs))
|
|
|
|
| 186 |
if __name__ == "__main__":
|
| 187 |
asyncio.run(embedding_service.initialize())
|
| 188 |
gr.mount_gradio_app(app, iface, path="/ui")
|
| 189 |
+
uvicorn.run("app:app", host="0.0.0.0", port=7860)
|