Spaces:
Sleeping
Sleeping
Download app.py from Loading404/legion-ai: direct link, hf CLI and curl.
- Browser
- Download file 1.07 kB
-
https://huggingface.co/spaces/Loading404/legion-ai/resolve/main/app.py
- Command line
-
hf download hf://spaces/Loading404/legion-ai/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Loading404/legion-ai/resolve/main/app.py
1.07 kB
| from flask import Flask, jsonify | |
| from price_fetcher import fetch_price | |
| from trend_engine import detect_trend | |
| from aws_logger import upload_to_s3 | |
| import threading | |
| import time | |
| from datetime import datetime | |
| app = Flask(__name__) | |
| latest_signal = {"price": 0.0, "trend": "⏳ Waiting..."} | |
| def background_refresh(): | |
| global latest_signal | |
| while True: | |
| price = fetch_price() | |
| trend = detect_trend(price) | |
| latest_signal = { | |
| "price": round(price, 4), | |
| "trend": trend, | |
| "timestamp": datetime.utcnow().isoformat() | |
| } | |
| upload_to_s3(latest_signal) | |
| time.sleep(60) | |
| def home(): | |
| return jsonify({ | |
| "message": "✅ Legion AI is running. Use /status for trend data.", | |
| "endpoints": ["/status"] | |
| }) | |
| def status(): | |
| return jsonify(latest_signal) | |
| if __name__ == "__main__": | |
| thread = threading.Thread(target=background_refresh) | |
| thread.daemon = True | |
| thread.start() | |
| app.run(host="0.0.0.0", port=7860) |