Upload kb_server.py with huggingface_hub
Browse files- kb_server.py +36 -0
kb_server.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Simple KB HTTP server for Krevetka on HF Space.
|
| 3 |
+
Serves /app/kb/ directory on port 8811.
|
| 4 |
+
Replaces the 192.168.0.5:8811 local server.
|
| 5 |
+
"""
|
| 6 |
+
import os
|
| 7 |
+
from flask import Flask, send_from_directory, jsonify
|
| 8 |
+
|
| 9 |
+
KB_DIR = "/app/kb"
|
| 10 |
+
app = Flask(__name__)
|
| 11 |
+
|
| 12 |
+
@app.route("/")
|
| 13 |
+
def list_dir():
|
| 14 |
+
"""Directory listing (matches original server format)."""
|
| 15 |
+
items = []
|
| 16 |
+
for entry in sorted(os.listdir(KB_DIR)):
|
| 17 |
+
full = os.path.join(KB_DIR, entry)
|
| 18 |
+
if os.path.isdir(full):
|
| 19 |
+
items.append(f'{entry}/')
|
| 20 |
+
else:
|
| 21 |
+
items.append(entry)
|
| 22 |
+
return '<!DOCTYPE HTML><html><body><ul>' + \
|
| 23 |
+
''.join(f'<li><a href="{i}">{i}</a></li>' for i in items) + \
|
| 24 |
+
'</ul></body></html>'
|
| 25 |
+
|
| 26 |
+
@app.route("/<path:filepath>")
|
| 27 |
+
def serve_file(filepath):
|
| 28 |
+
"""Serve any KB file."""
|
| 29 |
+
return send_from_directory(KB_DIR, filepath)
|
| 30 |
+
|
| 31 |
+
@app.route("/health")
|
| 32 |
+
def health():
|
| 33 |
+
return jsonify({"status": "ok"})
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
app.run(host="0.0.0.0", port=8811)
|