Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import pandas as pd | |
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| import io | |
| def trading_dashboard(digit, bias, digit_bias_list, bias_file, digit_sequence): | |
| # Bias interpretation + gauge zone | |
| if bias < 30: | |
| bias_msg = f"Bias {bias}% β Weak (Red Zone)" | |
| gauge_color = "red" | |
| elif 30 <= bias < 60: | |
| bias_msg = f"Bias {bias}% β Moderate (Yellow Zone)" | |
| gauge_color = "yellow" | |
| else: | |
| bias_msg = f"Bias {bias}% β Strong (Green Zone)" | |
| gauge_color = "green" | |
| # --- Bias Gauge Plot --- | |
| fig_gauge, axg = plt.subplots(figsize=(4,1)) | |
| axg.barh(["Bias"], [bias], color=gauge_color) | |
| axg.set_xlim(0,100) | |
| axg.set_title("Bias Strength Gauge") | |
| axg.set_xlabel("%") | |
| for spine in axg.spines.values(): | |
| spine.set_visible(False) | |
| # --- Digit Bias Analyzer (0β9 bar chart) --- | |
| if bias_file is not None: | |
| try: | |
| df = pd.read_csv(bias_file) if bias_file.name.endswith(".csv") else pd.read_excel(bias_file) | |
| digit_bias_values = df.iloc[0].values.tolist()[:10] | |
| except Exception: | |
| digit_bias_values = np.random.randint(0,100,10) | |
| elif digit_bias_list is not None and len(digit_bias_list) == 10: | |
| digit_bias_values = digit_bias_list | |
| else: | |
| digit_bias_values = np.random.randint(0,100,10) | |
| fig_digits, axd = plt.subplots() | |
| axd.bar(range(10), digit_bias_values, color="skyblue") | |
| axd.set_xticks(range(10)) | |
| axd.set_xticklabels([str(i) for i in range(10)]) | |
| axd.set_title("Digit Bias Analyzer (0β9)") | |
| axd.set_ylabel("Bias %") | |
| # --- Digit Psychology Module --- | |
| streaks = [] | |
| bias_summary = {} | |
| if digit_sequence: | |
| digits = [int(d) for d in str(digit_sequence) if d.isdigit()] | |
| if digits: | |
| # Streak awareness | |
| current_streak = 1 | |
| for i in range(1, len(digits)): | |
| if digits[i] == digits[i-1]: | |
| current_streak += 1 | |
| else: | |
| streaks.append((digits[i-1], current_streak)) | |
| current_streak = 1 | |
| streaks.append((digits[-1], current_streak)) | |
| # Bias summary (frequency %) | |
| freq = pd.Series(digits).value_counts(normalize=True) * 100 | |
| bias_summary = freq.to_dict() | |
| psychology_text = "π Digit Psychology Analysis\n\n" | |
| if streaks: | |
| psychology_text += "Streaks:\n" + "\n".join([f"Digit {d} β {s} times" for d,s in streaks]) + "\n\n" | |
| if bias_summary: | |
| psychology_text += "Bias Summary (%):\n" + "\n".join([f"Digit {d}: {round(p,1)}%" for d,p in bias_summary.items()]) + "\n\n" | |
| psychology_text += "Checklist:\n- Bias > 30%\n- Streak awareness checked\n- Indicators aligned (MACD/RSI)\n- Candle confirmation done" | |
| # Example market data | |
| data = pd.DataFrame(np.random.randn(50, 3), columns=['Price', 'Volume', 'Signal']) | |
| data['MACD'] = data['Price'].ewm(span=12).mean() - data['Price'].ewm(span=26).mean() | |
| data['RSI'] = 100 - (100 / (1 + (data['Price'].diff().clip(lower=0).rolling(14).mean() / | |
| data['Price'].diff().clip(upper=0).abs().rolling(14).mean()))) | |
| # Plot MACD | |
| fig1, ax1 = plt.subplots() | |
| ax1.plot(data['Price'], label="Price") | |
| ax1.plot(data['MACD'], label="MACD", color="orange") | |
| ax1.set_title("Price vs MACD") | |
| ax1.legend() | |
| # Plot RSI | |
| fig2, ax2 = plt.subplots() | |
| ax2.plot(data['RSI'], label="RSI", color="green") | |
| ax2.axhline(70, linestyle="--", color="red") | |
| ax2.axhline(30, linestyle="--", color="blue") | |
| ax2.set_title("RSI Indicator") | |
| ax2.legend() | |
| # Checklist summary | |
| checklist = [ | |
| "Bias > 30%", | |
| "Even/Odd bias matches entry", | |
| "Over/Under bias matches entry", | |
| "Indicators aligned (MACD/RSI)", | |
| "Final candle confirmation" | |
| ] | |
| # Master Trading Board Poster text | |
| poster = """ | |
| π Master Trading Board Poster | |
| Bias Rules: | |
| - Trade only if Bias > 30% | |
| - Strong bias preferred (>60%) | |
| Even/Odd Rules: | |
| - Trade EVEN if bias favors even digits | |
| - Trade ODD if bias favors odd digits | |
| Over/Under Rules: | |
| - Trade OVER if bias favors digits 5β9 | |
| - Trade UNDER if bias favors digits 0β4 | |
| Indicator Rules: | |
| - MACD confirms trend | |
| - RSI not overbought/oversold | |
| - Candle pattern matches strategy | |
| """ | |
| # --- Export results to CSV --- | |
| export_df = pd.DataFrame({ | |
| "Digit Bias Values": digit_bias_values, | |
| "Checklist": checklist | |
| }) | |
| buffer = io.StringIO() | |
| export_df.to_csv(buffer, index=False) | |
| buffer.seek(0) | |
| return bias_msg, fig_gauge, fig_digits, fig1, fig2, checklist, poster, psychology_text, buffer | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| with gr.Column(): | |
| digit = gr.Number(label="Digit (0β9)") | |
| bias = gr.Slider(0, 100, step=5, label="Bias %") | |
| digit_bias_list = gr.Dataframe(headers=[str(i) for i in range(10)], row_count=1, col_count=10, | |
| label="Digit Bias Input (0β9)", type="numpy") | |
| bias_file = gr.File(label="Upload Bias Data (CSV/Excel)", file_types=[".csv", ".xlsx"]) | |
| digit_sequence = gr.Textbox(label="Digit Sequence (e.g. 1234555777)") | |
| bias_out = gr.Textbox(label="Bias Interpretation") | |
| gauge_plot = gr.Plot(label="Bias Gauge") | |
| digit_bias_plot = gr.Plot(label="Digit Bias Analyzer") | |
| macd_plot = gr.Plot(label="MACD Chart") | |
| rsi_plot = gr.Plot(label="RSI Chart") | |
| psychology_out = gr.Textbox(label="Digit Psychology") | |
| download_out = gr.File(label="Download Results (CSV)") | |
| with gr.Column(): | |
| checklist_out = gr.Label(label="Checklist") | |
| poster_out = gr.Textbox(label="Master Trading Board Poster") | |
| demo.load(trading_dashboard, | |
| inputs=[digit, bias, digit_bias_list, bias_file, digit_sequence], | |
| outputs=[bias_out, gauge_plot, digit_bias_plot, macd_plot, rsi_plot, checklist_out, poster_out, psychology_out, download_out]) | |
| demo.launch() |