-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapp.py
More file actions
94 lines (72 loc) · 2.65 KB
/
app.py
File metadata and controls
94 lines (72 loc) · 2.65 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from flask import Flask, request, jsonify,send_file
from agent2 import Agents
from io import BytesIO
import base64
app = Flask(__name__)
@app.route('/generate_scenario', methods=['POST'])
def generate_scenario():
user_input = request.json.get('user_input', '')
mission_type = request.json.get('mission_type', 'px4')
if not user_input:
return jsonify({"error": "User input is required."}), 400
scenario_response, context, mission_json_list, environment_json_list = Agents.main(user_input,mission_type)
#
file1_path = f"user_questions/{user_input}_1.csv"
return jsonify({
"scenario_response": scenario_response,
"context": context,
"mission_details": mission_json_list,
"environment_details": environment_json_list,
"file1": file1_path
})
@app.route('/download/<path:filename>', methods=['GET'])
def download_file(filename):
try:
return send_file(filename, as_attachment=True)
except Exception as e:
return str(e), 404
@app.route('/analyze', methods=['POST'])
def analyze():
analytics_input = request.json.get('analytics_input', '')
if not analytics_input:
return jsonify({"error": "Analytics input is required."}), 400
text, images,Analysis = Agents.Analytics_three(analytics_input)
torch.cuda.empty_cache()
image_data = []
for image in images:
buffered = BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode()
image_data.append(img_str)
return jsonify({
"analysis_result1": text,
"analysis_result2": image_data,
"analysis_report" : Analysis,
})
@app.route('/newanalytics', methods=['POST'])
def newanalytics():
analytics_input = request.json.get('analytics_input', '')
images ,response = Agents.new_analytics(analytics_input)
torch.cuda.empty_cache()
print(images)
image_data = []
for image in images:
buffered = BytesIO()
image.save(buffered, format="PNG")
img_str = base64.b64encode(buffered.getvalue()).decode()
image_data.append(img_str)
return jsonify({
"output_one": image_data,
"output_two": response
})
@app.route('/deepdiverequest', methods=['POST'])
def deepdiverequest():
deep_dive_input1 = request.json.get('deep_dive_input1', '')
deep_dive_input2 = request.json.get('deep_dive_input2', '')
response = Agents.clarification(deep_dive_input1,deep_dive_input2)
torch.cuda.empty_cache()
return jsonify({
"output_one": response,
})
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0', port=5000)