Girnor / app.py
3VVM's picture
Update app.py
a05503d verified
Raw
History Blame Contribute Delete
4.97 kB
# app.py β€” Hugging Face Gradio Wrapper (Fixed v2)
import os, sys, io, warnings, traceback
warnings.filterwarnings("ignore")
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
os.environ["OMP_NUM_THREADS"] = "2"
import gradio as gr
# ── Load indicator file ────────────────────────────────────────────────────────
_ns = {}
LOAD_OK = False
LOAD_ERR = ""
try:
with open("advanced_indicator.py", "r") as f:
exec(compile(f.read(), "advanced_indicator.py", "exec"), _ns)
for k, v in _ns.items():
if not k.startswith("__"):
globals()[k] = v
INDICATOR = AdvancedIndicator()
DISPLAY = Display()
LOAD_OK = True
except Exception:
LOAD_ERR = traceback.format_exc()
# ── Core analysis function ─────────────────────────────────────────────────────
def analyse(symbol, timeframe, market_scan, top_n, lookback):
if not LOAD_OK:
return f"❌ Indicator load failed:\n\n{LOAD_ERR}"
buf = io.StringIO()
sys.stdout = buf
try:
sym = (symbol or "").strip().upper()
if market_scan != "None":
results = INDICATOR.scan_market(market_scan, timeframe, int(top_n))
DISPLAY.scan_table(results)
if results:
print("\n── Top Signal Detail ──\n")
DISPLAY.result(results[0], verbose=True)
else:
print("No strong signals found. Try different timeframe.")
elif sym:
result = INDICATOR.analyze(sym, timeframe, int(lookback))
if result:
DISPLAY.result(result, verbose=True)
else:
print(f"❌ No data for: {sym}\n"
f"Valid examples: EURUSD=X BTC-USD GBPJPY=X ETH-USD")
else:
print("⚠️ Symbol daalo (e.g. EURUSD=X) ya Market Scan select karo.")
except Exception:
print(f"Runtime Error:\n{traceback.format_exc()}")
finally:
out = buf.getvalue()
sys.stdout = sys.__stdout__
return out or "No output generated."
# ── Gradio UI ──────────────────────────────────────────────────────────────────
with gr.Blocks(title="Advanced Forex & Crypto Indicator") as app:
gr.Markdown("""
# πŸ“Š Advanced Forex & Crypto Trading Indicator v3.0
**Signals:** 🟒 BUY  |  πŸ”΄ SELL  |  βšͺ NEUTRAL
**Analysis:** 35+ TA Β· ML Ensemble (RF + ET + XGB + LGB + MLP) Β· Wavelet Β· Fourier Β· Hurst
**Timezone:** IST (UTC+5:30)  |  **Forex:** 30 pairs  |  **Crypto:** 23 pairs
""")
with gr.Row():
symbol_inp = gr.Textbox(
label="πŸ“Œ Symbol",
placeholder="EURUSD=X | BTC-USD | GBPJPY=X | ETH-USD",
value="EURUSD=X",
scale=3
)
tf_inp = gr.Dropdown(
choices=["30s","1m","2m","3m","5m","10m","15m","30m","1h","2h"],
value="15m",
label="⏱ Timeframe",
scale=1
)
with gr.Row():
scan_inp = gr.Dropdown(
choices=["None", "forex", "crypto"],
value="None",
label="πŸ” Market Scan (optional)",
scale=1
)
topn_inp = gr.Slider(1, 10, value=5, step=1,
label="Top N Signals (scan only)",
scale=1)
lookback_inp = gr.Slider(100, 500, value=300, step=50,
label="Lookback Bars",
scale=1)
run_btn = gr.Button("πŸš€ Analyse / Scan", variant="primary")
output = gr.Textbox(
label="πŸ“‹ Result",
lines=45,
max_lines=100
)
run_btn.click(
fn=analyse,
inputs=[symbol_inp, tf_inp, scan_inp, topn_inp, lookback_inp],
outputs=output
)
gr.Examples(
label="⚑ Quick Examples (click to load)",
examples=[
["EURUSD=X", "15m", "None", 5, 300],
["BTC-USD", "5m", "None", 5, 300],
["GBPJPY=X", "1h", "None", 5, 300],
["USDJPY=X", "30m", "None", 5, 300],
["ETH-USD", "15m", "None", 5, 300],
["XAUUSD=X", "1h", "None", 5, 300],
["", "15m", "forex", 5, 300],
["", "15m", "crypto", 5, 300],
],
inputs=[symbol_inp, tf_inp, scan_inp, topn_inp, lookback_inp],
)
gr.Markdown("""
---
⚠️ **Disclaimer:** Educational purpose only. Apni research se trading decisions lena.
πŸ“‘ **Data:** Yahoo Finance (real-time)
""")
app.launch(server_name="0.0.0.0", server_port=7860)