|
import os |
|
import gradio as gr |
|
import xgboost as xgb |
|
import numpy as np |
|
import pandas as pd |
|
import requests |
|
from huggingface_hub import hf_hub_download |
|
|
|
|
|
if not os.path.exists("processed_data.csv"): |
|
print("📌 运行 `preprocess.py` 进行数据处理...") |
|
os.system("python preprocess.py") |
|
|
|
|
|
processed_data_path = "processed_data.csv" |
|
if not os.path.exists(processed_data_path): |
|
raise FileNotFoundError("❌ `processed_data.csv` 未找到,请先运行 `preprocess.py` 处理数据!") |
|
|
|
df = pd.read_csv(processed_data_path) |
|
|
|
|
|
model_path = hf_hub_download(repo_id="YDluffy/lottery_prediction", filename="lottery_xgboost_model.json") |
|
model = xgb.XGBRegressor() |
|
model.load_model(model_path) |
|
|
|
|
|
LLM_API_URL = "https://your-llm-space.gradio.app" |
|
|
|
def get_prediction_from_llm(user_input): |
|
|
|
response = requests.post(LLM_API_URL + "/api/predict", json={"input": user_input}) |
|
llm_output = response.json().get("prediction", "") |
|
|
|
|
|
year, period = 2025, 16 |
|
nums = [5, 12, 23, 34, 45, 56] |
|
special = 7 |
|
|
|
|
|
prediction = predict_lottery(year, period, *nums, special) |
|
|
|
return f"预测的号码是: {prediction}\n\n模型解析的特征:{llm_output}" |
|
|
|
|
|
def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special): |
|
|
|
history = df[(df['期号_年份'] == year) & (df['期数'] == period)] |
|
if not history.empty: |
|
month = history.iloc[0]['月份'] |
|
day = history.iloc[0]['日期'] |
|
else: |
|
month, day = 1, 1 |
|
|
|
|
|
avg_number = np.mean([num1, num2, num3, num4, num5, num6]) |
|
|
|
|
|
features = np.array([[year, period, month, day, num1, num2, num3, num4, num5, num6, special, avg_number]]) |
|
|
|
|
|
prediction = model.predict(features) |
|
return prediction |
|
|
|
|
|
iface = gr.Interface( |
|
fn=get_prediction_from_llm, |
|
inputs=gr.Textbox(label="请输入问题或期号信息"), |
|
outputs="text", |
|
title="六合彩预测模型", |
|
description="通过与 LLM 交互,解析输入信息并进行预测" |
|
) |
|
|
|
|
|
iface.launch(share=True) |
|
|