Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
+
from flask_cors import CORS
|
3 |
+
import uuid
|
4 |
+
import time
|
5 |
+
|
6 |
+
app = Flask(__name__)
|
7 |
+
CORS(app)
|
8 |
+
|
9 |
+
# In-memory log store: { id: { ip, location, messages, timestamps } }
|
10 |
+
LOG_STORE = {}
|
11 |
+
|
12 |
+
@app.route("/api/log", methods=["POST"])
|
13 |
+
def store_log():
|
14 |
+
try:
|
15 |
+
data = request.json
|
16 |
+
log_id = str(uuid.uuid4())
|
17 |
+
LOG_STORE[log_id] = {
|
18 |
+
"ip": data.get("ip"),
|
19 |
+
"location": data.get("location"),
|
20 |
+
"message": data.get("message"),
|
21 |
+
"timestamp": time.time(),
|
22 |
+
"label": data.get("label") # e.g. "Terrorism", "Blackmail"
|
23 |
+
}
|
24 |
+
return jsonify({"status": "stored", "id": log_id})
|
25 |
+
except Exception as e:
|
26 |
+
return jsonify({"error": str(e)}), 400
|
27 |
+
|
28 |
+
@app.route("/api/logs", methods=["GET"])
|
29 |
+
def get_logs():
|
30 |
+
return jsonify(LOG_STORE)
|
31 |
+
|
32 |
+
@app.route("/")
|
33 |
+
def home():
|
34 |
+
return "✅ Flagged Chat Log Store is Running"
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
app.run(host="0.0.0.0", port=7860)
|