dev-box / kb_server.py
ameobius's picture
Upload kb_server.py with huggingface_hub
526f61b verified
Raw History Blame Contribute Delete
1.01 kB
#!/usr/bin/env python3
"""Simple KB HTTP server for Krevetka on HF Space.
Serves /app/kb/ directory on port 8811.
Replaces the 192.168.0.5:8811 local server.
"""
import os
from flask import Flask, send_from_directory, jsonify
KB_DIR = "/app/kb"
app = Flask(__name__)
@app.route("/")
def list_dir():
"""Directory listing (matches original server format)."""
items = []
for entry in sorted(os.listdir(KB_DIR)):
full = os.path.join(KB_DIR, entry)
if os.path.isdir(full):
items.append(f'{entry}/')
else:
items.append(entry)
return '<!DOCTYPE HTML><html><body><ul>' + \
''.join(f'<li><a href="{i}">{i}</a></li>' for i in items) + \
'</ul></body></html>'
@app.route("/<path:filepath>")
def serve_file(filepath):
"""Serve any KB file."""
return send_from_directory(KB_DIR, filepath)
@app.route("/health")
def health():
return jsonify({"status": "ok"})
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8811)