Spaces:
Sleeping
Sleeping
saifeddinemk
commited on
Commit
•
868dd10
1
Parent(s):
f620305
Fixed app v2
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
-
from fastapi import FastAPI, HTTPException
|
|
|
2 |
from llama_cpp import Llama
|
3 |
|
4 |
# Initialize FastAPI app
|
@@ -13,20 +14,24 @@ try:
|
|
13 |
except Exception as e:
|
14 |
raise RuntimeError(f"Failed to load model: {e}")
|
15 |
|
16 |
-
# Define
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
|
|
|
|
|
|
|
|
|
24 |
# Security-focused prompt
|
25 |
prompt = (
|
26 |
"Analyze the following network log data for any indicators of malicious activity, "
|
27 |
"such as unusual IP addresses, unauthorized access attempts, data exfiltration, or anomalies. "
|
28 |
"Provide details on potential threats, IPs involved, and suggest actions if any threats are detected.\n\n"
|
29 |
-
f"{log_data}"
|
30 |
)
|
31 |
|
32 |
# Generate response from the model
|
@@ -41,7 +46,7 @@ async def analyze_security_logs(file: UploadFile = File(...)):
|
|
41 |
|
42 |
# Extract and return the analysis text
|
43 |
analysis_text = response["choices"][0]["message"]["content"]
|
44 |
-
return
|
45 |
except Exception as e:
|
46 |
raise HTTPException(status_code=500, detail=str(e))
|
47 |
|
|
|
1 |
+
from fastapi import FastAPI, HTTPException
|
2 |
+
from pydantic import BaseModel
|
3 |
from llama_cpp import Llama
|
4 |
|
5 |
# Initialize FastAPI app
|
|
|
14 |
except Exception as e:
|
15 |
raise RuntimeError(f"Failed to load model: {e}")
|
16 |
|
17 |
+
# Define request model for log data
|
18 |
+
class LogRequest(BaseModel):
|
19 |
+
log_data: str
|
20 |
+
|
21 |
+
# Define response model
|
22 |
+
class AnalysisResponse(BaseModel):
|
23 |
+
analysis: str
|
24 |
|
25 |
+
# Define the route for security log analysis
|
26 |
+
@app.post("/analyze_security_logs", response_model=AnalysisResponse)
|
27 |
+
async def analyze_security_logs(request: LogRequest):
|
28 |
+
try:
|
29 |
# Security-focused prompt
|
30 |
prompt = (
|
31 |
"Analyze the following network log data for any indicators of malicious activity, "
|
32 |
"such as unusual IP addresses, unauthorized access attempts, data exfiltration, or anomalies. "
|
33 |
"Provide details on potential threats, IPs involved, and suggest actions if any threats are detected.\n\n"
|
34 |
+
f"{request.log_data}"
|
35 |
)
|
36 |
|
37 |
# Generate response from the model
|
|
|
46 |
|
47 |
# Extract and return the analysis text
|
48 |
analysis_text = response["choices"][0]["message"]["content"]
|
49 |
+
return AnalysisResponse(analysis=analysis_text)
|
50 |
except Exception as e:
|
51 |
raise HTTPException(status_code=500, detail=str(e))
|
52 |
|