|
import gradio as gr |
|
import xgboost as xgb |
|
import numpy as np |
|
import pandas as pd |
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
repo_id = "YDluffy/lottery_prediction" |
|
model_filename = "lottery_xgboost_model.ubj" |
|
model_path = hf_hub_download(repo_id=repo_id, filename=model_filename) |
|
|
|
|
|
model = xgb.Booster() |
|
model.load_model(model_path) |
|
|
|
|
|
history_data_path = "cleaned_mark_six.csv" |
|
history_data = pd.read_csv(history_data_path) |
|
|
|
|
|
def predict_lottery(year, period): |
|
|
|
historical_matches = history_data[history_data["期数"] == period] |
|
|
|
|
|
most_frequent_numbers = historical_matches.iloc[:, -7:].mode().iloc[0].tolist() |
|
|
|
|
|
test_features = np.array([[year, period] + most_frequent_numbers]) |
|
dtest = xgb.DMatrix(test_features) |
|
|
|
|
|
prediction = model.predict(dtest) |
|
final_prediction = np.round(prediction).astype(int).tolist() |
|
|
|
return final_prediction |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_lottery, |
|
inputs=["number", "number"], |
|
outputs="text", |
|
title="六合彩智能预测 API", |
|
description="输入年份和期数,自动分析历史开奖记录,预测开奖号码" |
|
) |
|
|
|
iface.launch(share=True) |
|
|