Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import xgboost as xgb
|
| 3 |
+
import numpy as np
|
| 4 |
+
from huggingface_hub import hf_hub_download
|
| 5 |
+
|
| 6 |
+
# **📥 从 Hugging Face 下载 XGBoost 模型**
|
| 7 |
+
repo_id = "YDluffy/lottery_prediction"
|
| 8 |
+
model_filename = "lottery_xgboost_model.ubj"
|
| 9 |
+
model_path = hf_hub_download(repo_id=repo_id, filename=model_filename)
|
| 10 |
+
|
| 11 |
+
# **✅ 加载 XGBoost 模型**
|
| 12 |
+
model = xgb.Booster()
|
| 13 |
+
model.load_model(model_path)
|
| 14 |
+
|
| 15 |
+
# **📌 预测函数**
|
| 16 |
+
def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
|
| 17 |
+
test_features = np.array([[year, period, 1, 1, num1, num2, num3, num4, num5, num6, special, 30]])
|
| 18 |
+
dtest = xgb.DMatrix(test_features)
|
| 19 |
+
prediction = model.predict(dtest)
|
| 20 |
+
final_prediction = np.round(prediction).astype(int).tolist()
|
| 21 |
+
return final_prediction
|
| 22 |
+
|
| 23 |
+
# **📌 创建 API 接口**
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=predict_lottery,
|
| 26 |
+
inputs=["number", "number", "number", "number", "number", "number", "number", "number", "number"],
|
| 27 |
+
outputs="text",
|
| 28 |
+
title="六合彩预测 API",
|
| 29 |
+
description="输入年份、期号和开奖号码,返回预测结果"
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
iface.launch(share=True)
|