File size: 1,014 Bytes
526f61b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/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)