-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathapp.py
More file actions
34 lines (28 loc) · 1 KB
/
app.py
File metadata and controls
34 lines (28 loc) · 1 KB
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
from flask import Flask, render_template, request, jsonify
from backend.main import search_tool
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/search', methods=['POST'])
def search_tools():
data = request.get_json()
query = data.get('query', '')
if not query:
return jsonify({'error': 'No query provided'}), 400
try:
results = search_tool(query)
# Convert results to a more JSON-friendly format
formatted_results = []
for tool in results:
formatted_results.append({
'name': tool[0],
'description': tool[1],
'link': tool[2] if len(tool) > 2 else '',
'category': tool[3] if len(tool) > 3 else ''
})
return jsonify({'results': formatted_results})
except Exception as e:
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=False)