Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from starlette.exceptions import HTTPException
|
5 |
+
from pydantic import BaseModel
|
6 |
+
|
7 |
+
import last_layer
|
8 |
+
|
9 |
+
app = FastAPI()
|
10 |
+
class Request(BaseModel):
|
11 |
+
text: str
|
12 |
+
|
13 |
+
|
14 |
+
@app.post("/scan-prompt/")
|
15 |
+
async def scan_prompt(chunk: Request) -> last_layer.RiskModel:
|
16 |
+
try:
|
17 |
+
result = await asyncio.to_thread(last_layer.scan_prompt, chunk.text)
|
18 |
+
return result
|
19 |
+
except Exception as e:
|
20 |
+
raise HTTPException(status_code=400, detail=f"An error occurred: {str(e)}")
|
21 |
+
|
22 |
+
|
23 |
+
@app.post("/scan-llm/")
|
24 |
+
async def scan_llm(chunk: Request):
|
25 |
+
return {"message": "None"}
|