Spaces:
Runtime error
Runtime error
creare main.py app
Browse files- app/main.py +29 -0
app/main.py
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
import subprocess
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
app = Flask(__name__)
|
| 7 |
+
|
| 8 |
+
@app.route("/analyze", methods=["POST"])
|
| 9 |
+
def analyze_signal():
|
| 10 |
+
data = request.get_json()
|
| 11 |
+
prompt = f"Analyze this trading signal:\n\n{json.dumps(data, indent=2)}"
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
result = subprocess.run(
|
| 15 |
+
["ollama", "run", "llama3", prompt],
|
| 16 |
+
capture_output=True,
|
| 17 |
+
text=True,
|
| 18 |
+
timeout=60
|
| 19 |
+
)
|
| 20 |
+
return jsonify({
|
| 21 |
+
"success": True,
|
| 22 |
+
"response": result.stdout.strip()
|
| 23 |
+
})
|
| 24 |
+
except Exception as e:
|
| 25 |
+
return jsonify({"success": False, "error": str(e)}), 500
|
| 26 |
+
|
| 27 |
+
@app.route("/")
|
| 28 |
+
def index():
|
| 29 |
+
return "Quant Signal LLM API is running."
|