Spaces:
Running on Zero
Running on Zero
Daniel Alnawaz commited on
back to gradio
Browse files- README.md +2 -1
- app.py +23 -90
- requirements.txt +0 -2
README.md
CHANGED
|
@@ -3,7 +3,8 @@ title: HypeAdvisor
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: pink
|
| 6 |
-
sdk:
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
|
|
|
| 3 |
emoji: π
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: pink
|
| 6 |
+
sdk: gradio
|
| 7 |
+
app_file: app.py
|
| 8 |
pinned: false
|
| 9 |
---
|
| 10 |
|
app.py
CHANGED
|
@@ -1,19 +1,11 @@
|
|
| 1 |
-
"""HypeAdvisor β HYPE swing-trade advisor for Hyperliquid.
|
| 2 |
-
|
| 3 |
-
Exposes:
|
| 4 |
-
- GET /api/v1/advice β JSON trade recommendation
|
| 5 |
-
- GET /api/v1/health β service health
|
| 6 |
-
- Gradio UI at / β interactive browser interface
|
| 7 |
-
"""
|
| 8 |
|
| 9 |
from __future__ import annotations
|
| 10 |
|
|
|
|
| 11 |
import logging
|
| 12 |
-
import os
|
| 13 |
import sys
|
| 14 |
import traceback
|
| 15 |
-
from datetime import datetime, timezone
|
| 16 |
-
from typing import Literal
|
| 17 |
|
| 18 |
logging.basicConfig(
|
| 19 |
level=logging.INFO,
|
|
@@ -26,79 +18,15 @@ log = logging.getLogger("hypeadvisor")
|
|
| 26 |
log.info("Starting HypeAdvisor β importing dependencies...")
|
| 27 |
|
| 28 |
import gradio as gr
|
| 29 |
-
from fastapi import FastAPI, Query
|
| 30 |
-
from fastapi.responses import JSONResponse
|
| 31 |
|
| 32 |
-
log.info("
|
| 33 |
|
| 34 |
from src.advisor import get_advice
|
| 35 |
-
from src.hyperliquid import Interval
|
| 36 |
-
|
| 37 |
-
log.info("Internal modules imported")
|
| 38 |
-
|
| 39 |
-
# ---------------------------------------------------------------------------
|
| 40 |
-
# FastAPI app
|
| 41 |
-
# ---------------------------------------------------------------------------
|
| 42 |
-
|
| 43 |
-
log.info("Building FastAPI app...")
|
| 44 |
-
fastapi_app = FastAPI(
|
| 45 |
-
title="HypeAdvisor",
|
| 46 |
-
description="Swing-trading advisor for HYPE on Hyperliquid, powered by Claude",
|
| 47 |
-
version="1.0.0",
|
| 48 |
-
)
|
| 49 |
-
|
| 50 |
-
_VALID_INTERVALS: list[Interval] = ["15m", "1h", "4h", "1d"]
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
@fastapi_app.get("/api/v1/health")
|
| 54 |
-
async def health():
|
| 55 |
-
return {"status": "ok", "timestamp": datetime.now(timezone.utc).isoformat()}
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
@fastapi_app.get("/api/v1/advice")
|
| 59 |
-
async def advice_endpoint(
|
| 60 |
-
interval: Literal["15m", "1h", "4h", "1d"] = Query(
|
| 61 |
-
default="4h", description="Candle timeframe"
|
| 62 |
-
),
|
| 63 |
-
lookback: int = Query(
|
| 64 |
-
default=200, ge=50, le=500, description="Number of candles to fetch"
|
| 65 |
-
),
|
| 66 |
-
atr_tp_mult: float = Query(
|
| 67 |
-
default=2.0, ge=0.5, le=10.0, description="ATR multiplier for take-profit"
|
| 68 |
-
),
|
| 69 |
-
atr_sl_mult: float = Query(
|
| 70 |
-
default=1.0, ge=0.5, le=5.0, description="ATR multiplier for stop-loss"
|
| 71 |
-
),
|
| 72 |
-
):
|
| 73 |
-
"""Return a LONG/SHORT/NEUTRAL recommendation for HYPE."""
|
| 74 |
-
try:
|
| 75 |
-
advice = get_advice(
|
| 76 |
-
coin="HYPE",
|
| 77 |
-
interval=interval,
|
| 78 |
-
lookback=lookback,
|
| 79 |
-
atr_tp_mult=atr_tp_mult,
|
| 80 |
-
atr_sl_mult=atr_sl_mult,
|
| 81 |
-
)
|
| 82 |
-
return JSONResponse(
|
| 83 |
-
content={
|
| 84 |
-
"ok": True,
|
| 85 |
-
"timestamp": datetime.now(timezone.utc).isoformat(),
|
| 86 |
-
"advice": advice.to_dict(),
|
| 87 |
-
}
|
| 88 |
-
)
|
| 89 |
-
except Exception as exc:
|
| 90 |
-
return JSONResponse(
|
| 91 |
-
status_code=500,
|
| 92 |
-
content={
|
| 93 |
-
"ok": False,
|
| 94 |
-
"error": str(exc),
|
| 95 |
-
"timestamp": datetime.now(timezone.utc).isoformat(),
|
| 96 |
-
},
|
| 97 |
-
)
|
| 98 |
|
|
|
|
| 99 |
|
| 100 |
# ---------------------------------------------------------------------------
|
| 101 |
-
# Gradio
|
| 102 |
# ---------------------------------------------------------------------------
|
| 103 |
|
| 104 |
_DIRECTION_COLOR = {"LONG": "#00c853", "SHORT": "#ff1744", "NEUTRAL": "#ffab00"}
|
|
@@ -106,12 +34,12 @@ _CONFIDENCE_EMOJI = {"HIGH": "π₯", "MEDIUM": "π‘", "LOW": "βͺ"}
|
|
| 106 |
|
| 107 |
|
| 108 |
def _run_advisor(interval: str, lookback: int, atr_tp: float, atr_sl: float) -> tuple:
|
| 109 |
-
"
|
| 110 |
try:
|
| 111 |
advice = get_advice(
|
| 112 |
coin="HYPE",
|
| 113 |
interval=interval,
|
| 114 |
-
lookback=lookback,
|
| 115 |
atr_tp_mult=atr_tp,
|
| 116 |
atr_sl_mult=atr_sl,
|
| 117 |
)
|
|
@@ -157,22 +85,28 @@ def _run_advisor(interval: str, lookback: int, atr_tp: float, atr_sl: float) ->
|
|
| 157 |
</small>
|
| 158 |
</div>"""
|
| 159 |
|
| 160 |
-
|
| 161 |
-
return summary,
|
| 162 |
|
| 163 |
except Exception:
|
| 164 |
err = traceback.format_exc()
|
|
|
|
| 165 |
return f"<pre style='color:red;'>{err}</pre>", "{}"
|
| 166 |
|
| 167 |
|
| 168 |
-
|
|
|
|
|
|
|
| 169 |
|
| 170 |
-
with gr.Blocks(
|
| 171 |
-
|
| 172 |
-
|
|
|
|
| 173 |
body { background: #0d0d1a; }
|
| 174 |
.gradio-container { max-width: 900px; margin: 0 auto; }
|
| 175 |
-
"""
|
|
|
|
|
|
|
| 176 |
gr.Markdown(
|
| 177 |
"""
|
| 178 |
# β‘ HypeAdvisor
|
|
@@ -214,7 +148,6 @@ with gr.Blocks(title="HypeAdvisor") as demo:
|
|
| 214 |
"""
|
| 215 |
)
|
| 216 |
|
| 217 |
-
log.info("
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
log.info("App ready β waiting for server to accept connections")
|
|
|
|
| 1 |
+
"""HypeAdvisor β HYPE swing-trade advisor for Hyperliquid."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
+
import json
|
| 6 |
import logging
|
|
|
|
| 7 |
import sys
|
| 8 |
import traceback
|
|
|
|
|
|
|
| 9 |
|
| 10 |
logging.basicConfig(
|
| 11 |
level=logging.INFO,
|
|
|
|
| 18 |
log.info("Starting HypeAdvisor β importing dependencies...")
|
| 19 |
|
| 20 |
import gradio as gr
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
log.info("Gradio imported")
|
| 23 |
|
| 24 |
from src.advisor import get_advice
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
log.info("Internal modules imported β building UI...")
|
| 27 |
|
| 28 |
# ---------------------------------------------------------------------------
|
| 29 |
+
# Gradio callback
|
| 30 |
# ---------------------------------------------------------------------------
|
| 31 |
|
| 32 |
_DIRECTION_COLOR = {"LONG": "#00c853", "SHORT": "#ff1744", "NEUTRAL": "#ffab00"}
|
|
|
|
| 34 |
|
| 35 |
|
| 36 |
def _run_advisor(interval: str, lookback: int, atr_tp: float, atr_sl: float) -> tuple:
|
| 37 |
+
log.info("Request: interval=%s lookback=%d atr_tp=%.2f atr_sl=%.2f", interval, lookback, atr_tp, atr_sl)
|
| 38 |
try:
|
| 39 |
advice = get_advice(
|
| 40 |
coin="HYPE",
|
| 41 |
interval=interval,
|
| 42 |
+
lookback=int(lookback),
|
| 43 |
atr_tp_mult=atr_tp,
|
| 44 |
atr_sl_mult=atr_sl,
|
| 45 |
)
|
|
|
|
| 85 |
</small>
|
| 86 |
</div>"""
|
| 87 |
|
| 88 |
+
log.info("Response: %s %s", d["direction"], d["confidence"])
|
| 89 |
+
return summary, json.dumps(d, indent=2)
|
| 90 |
|
| 91 |
except Exception:
|
| 92 |
err = traceback.format_exc()
|
| 93 |
+
log.error("Advisor failed:\n%s", err)
|
| 94 |
return f"<pre style='color:red;'>{err}</pre>", "{}"
|
| 95 |
|
| 96 |
|
| 97 |
+
# ---------------------------------------------------------------------------
|
| 98 |
+
# Gradio UI
|
| 99 |
+
# ---------------------------------------------------------------------------
|
| 100 |
|
| 101 |
+
with gr.Blocks(
|
| 102 |
+
title="HypeAdvisor",
|
| 103 |
+
theme=gr.themes.Base(primary_hue="blue", neutral_hue="slate"),
|
| 104 |
+
css="""
|
| 105 |
body { background: #0d0d1a; }
|
| 106 |
.gradio-container { max-width: 900px; margin: 0 auto; }
|
| 107 |
+
""",
|
| 108 |
+
analytics_enabled=False,
|
| 109 |
+
) as demo:
|
| 110 |
gr.Markdown(
|
| 111 |
"""
|
| 112 |
# β‘ HypeAdvisor
|
|
|
|
| 148 |
"""
|
| 149 |
)
|
| 150 |
|
| 151 |
+
log.info("UI built β launching server...")
|
| 152 |
+
|
| 153 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
requirements.txt
CHANGED
|
@@ -1,7 +1,5 @@
|
|
| 1 |
-
fastapi>=0.115.0
|
| 2 |
gradio>=5.0.0
|
| 3 |
httpx>=0.27.0
|
| 4 |
huggingface_hub>=0.24.0
|
| 5 |
numpy>=1.26.0
|
| 6 |
pandas>=2.2.0
|
| 7 |
-
uvicorn>=0.30.0
|
|
|
|
|
|
|
| 1 |
gradio>=5.0.0
|
| 2 |
httpx>=0.27.0
|
| 3 |
huggingface_hub>=0.24.0
|
| 4 |
numpy>=1.26.0
|
| 5 |
pandas>=2.2.0
|
|
|