Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Initialize the FastAPI app
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
# Initialize the model pipeline
|
9 |
+
pipe = pipeline("text-classification", model="kmack/malicious-url-detection")
|
10 |
+
|
11 |
+
# Define the request model
|
12 |
+
class URLRequest(BaseModel):
|
13 |
+
url: str
|
14 |
+
|
15 |
+
# Define the API endpoint for URL prediction
|
16 |
+
@app.post("/predict")
|
17 |
+
async def predict(url_request: URLRequest):
|
18 |
+
url_to_check = url_request.url
|
19 |
+
result = pipe(url_to_check)
|
20 |
+
return {"prediction": result}
|
21 |
+
|
22 |
+
# Health check endpoint
|
23 |
+
@app.get("/")
|
24 |
+
async def read_root():
|
25 |
+
return {"message": "API is up and running"}
|