File size: 761 Bytes
729d130
751678e
729d130
 
 
751678e
804ddc3
729d130
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import json
import os
from flask import Flask, jsonify, request
from semantic_search import SemanticSearch


search = SemanticSearch()
search.test_search()

app = Flask(__name__)
app.config['JSON_AS_ASCII'] = False

@app.route('/health', methods=['GET'])
def health():
    return jsonify({"status": "ok"})

@app.route('/search', methods=['POST'])
def search_route():
    data = request.get_json()
    query = data.get('query', '')
    top = data.get('top', 10)
    titles, docs, scores = search.search(query, top)
    result = [{'title': str(item1), 'text': str(item2), 'relevance': str(item3)} for item1, item2, item3 in zip(titles, docs, scores)]
    return jsonify(result)

if __name__ == '__main__':
    
    app.run(debug=False, host='0.0.0.0', port=7868)