Spaces:
Sleeping
Sleeping
| import pandas as pd | |
| import numpy as np | |
| import os | |
| import gradio as gr | |
| # Function to apply DOS Rules | |
| def apply_dos_rules(data, lookback): | |
| numbers = data[['N1', 'N2', 'N3', 'N4', 'N5']].values.flatten() | |
| unique, counts = np.unique(numbers, return_counts=True) | |
| freq = dict(zip(unique, counts)) | |
| good_numbers = [] | |
| for num, count in freq.items(): | |
| if count >= 1: | |
| good_numbers.append(num) | |
| odds = [n for n in good_numbers if n % 2 == 1] | |
| evens = [n for n in good_numbers if n % 2 == 0] | |
| if len(odds) >= 3 and len(evens) >= 2: | |
| final_set = ( | |
| np.random.choice(odds, 3, replace=False).tolist() + | |
| np.random.choice(evens, 2, replace=False).tolist() | |
| ) | |
| elif len(odds) >= 2 and len(evens) >= 3: | |
| final_set = ( | |
| np.random.choice(odds, 2, replace=False).tolist() + | |
| np.random.choice(evens, 3, replace=False).tolist() | |
| ) | |
| else: | |
| final_set = np.random.choice(good_numbers, 5, replace=False).tolist() | |
| return sorted(final_set) | |
| # Main function for Gradio (Show only predictions) | |
| def predict_numbers(file, lookback_choice): | |
| df = pd.read_csv(file) | |
| df = df.dropna() | |
| df.columns = ['Date', 'N1', 'N2', 'N3', 'N4', 'N5'] | |
| df['Date'] = pd.to_datetime(df['Date']) | |
| df = df.sort_values('Date', ascending=False).reset_index(drop=True) | |
| lookback = len(df) if lookback_choice.lower() == "all" else int(lookback_choice) | |
| subset = df.head(lookback) | |
| prediction = apply_dos_rules(subset, lookback) | |
| return f"🎯 Predicted Set:\n{prediction}" | |
| # Path to your uploaded logo | |
| logo_path = "IMG_4963.jpeg" # Ensure this image is in the same directory as app.py | |
| # Gradio UI | |
| with gr.Blocks() as demo: | |
| with gr.Row(): | |
| gr.Image(value=logo_path, label="", show_label=False, elem_id="logo", height=120) | |
| gr.Markdown("## 🎲 Lottery Prediction using DOS Rules") | |
| with gr.Row(): | |
| file_input = gr.File(label="Upload Lottery CSV", file_types=[".csv"]) | |
| lookback_input = gr.Radio(choices=["12", "15", "20", "All"], label="Select Lookback", value="12") | |
| output = gr.Textbox(label="Prediction Result", lines=5) | |
| btn = gr.Button("Predict") | |
| btn.click(predict_numbers, inputs=[file_input, lookback_input], outputs=output) | |
| # Detect if running on Hugging Face | |
| is_hf = os.environ.get("SPACE_ID") is not None | |
| if is_hf: | |
| demo.launch() | |
| else: | |
| demo.launch(share=True) | |