File size: 4,972 Bytes
a05503d
3423d23
5967686
3423d23
a05503d
3423d23
 
5967686
a05503d
3423d23
a05503d
 
 
3423d23
 
 
 
 
 
 
 
 
a05503d
3423d23
5967686
a05503d
3423d23
 
a05503d
5967686
 
 
a05503d
5967686
a05503d
 
5967686
3423d23
 
5967686
a05503d
3423d23
 
a05503d
 
3423d23
 
5967686
3423d23
5967686
a05503d
 
3423d23
a05503d
 
 
 
 
3423d23
 
 
a05503d
 
3423d23
 
a05503d
5967686
 
3423d23
 
a05503d
3423d23
5967686
 
 
a05503d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5967686
3423d23
 
 
a05503d
3423d23
 
 
 
 
 
 
5967686
 
a05503d
5967686
a05503d
 
 
 
 
 
3423d23
 
5967686
3423d23
5967686
 
3423d23
 
a05503d
 
3423d23
 
 
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# 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)