Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import os
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
UPLOAD_DIR = "/data/uploads"
|
| 6 |
+
PROCESSED_DIR = "/data/processed"
|
| 7 |
+
os.makedirs(PROCESSED_DIR, exist_ok=True)
|
| 8 |
+
|
| 9 |
+
def process_log(file_path):
|
| 10 |
+
# Dummy anomaly detection logic; replace with your real pipeline
|
| 11 |
+
# For example, call your detect_anomalies_and_explain here
|
| 12 |
+
return {"filename": os.path.basename(file_path), "anomaly": True, "details": "Example anomaly detected."}
|
| 13 |
+
|
| 14 |
+
def save_rca_to_db(rca_result):
|
| 15 |
+
# Replace with actual DB insert logic (e.g., via RCA API or direct DB connection)
|
| 16 |
+
requests.post("http://rca_api:8000/rca/", json=rca_result)
|
| 17 |
+
|
| 18 |
+
def main():
|
| 19 |
+
processed_files = set()
|
| 20 |
+
while True:
|
| 21 |
+
for filename in os.listdir(UPLOAD_DIR):
|
| 22 |
+
file_path = os.path.join(UPLOAD_DIR, filename)
|
| 23 |
+
if filename not in processed_files and os.path.isfile(file_path):
|
| 24 |
+
rca_result = process_log(file_path)
|
| 25 |
+
save_rca_to_db(rca_result)
|
| 26 |
+
processed_files.add(filename)
|
| 27 |
+
time.sleep(5)
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
main()
|