YDluffy commited on
Commit
48b6405
·
verified ·
1 Parent(s): bbb136d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -9
app.py CHANGED
@@ -3,9 +3,10 @@ import gradio as gr
3
  import xgboost as xgb
4
  import numpy as np
5
  import pandas as pd
 
6
  from huggingface_hub import hf_hub_download
7
 
8
- # **📌 先运行 `preprocess.py` 进行数据处理**
9
  if not os.path.exists("processed_data.csv"):
10
  print("📌 运行 `preprocess.py` 进行数据处理...")
11
  os.system("python preprocess.py")
@@ -22,6 +23,24 @@ model_path = hf_hub_download(repo_id="YDluffy/lottery_prediction", filename="lot
22
  model = xgb.XGBRegressor()
23
  model.load_model(model_path)
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  # **📌 预测函数**
26
  def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
27
  # 从历史数据查找对应的月份和日期
@@ -44,16 +63,11 @@ def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
44
 
45
  # **📌 Gradio Web 界面**
46
  iface = gr.Interface(
47
- fn=predict_lottery,
48
- inputs=[
49
- gr.Number(label="年份"), gr.Number(label="期数"),
50
- gr.Number(label="号码1"), gr.Number(label="号码2"), gr.Number(label="号码3"),
51
- gr.Number(label="号码4"), gr.Number(label="号码5"), gr.Number(label="号码6"),
52
- gr.Number(label="特别号码")
53
- ],
54
  outputs="text",
55
  title="六合彩预测模型",
56
- description="输入期号和历史开奖号码,预测指定期开奖的号码"
57
  )
58
 
59
  # **📌 启动 Gradio 应用**
 
3
  import xgboost as xgb
4
  import numpy as np
5
  import pandas as pd
6
+ import requests
7
  from huggingface_hub import hf_hub_download
8
 
9
+ # **📌 先运行 `preprocess.py` 处理数据**
10
  if not os.path.exists("processed_data.csv"):
11
  print("📌 运行 `preprocess.py` 进行数据处理...")
12
  os.system("python preprocess.py")
 
23
  model = xgb.XGBRegressor()
24
  model.load_model(model_path)
25
 
26
+ # **📌 调用 LLM API 解析用户输入**
27
+ LLM_API_URL = "https://your-llm-space.gradio.app" # 替换为 LLM 服务器地址
28
+
29
+ def get_prediction_from_llm(user_input):
30
+ # 调用 LLM 提取预测所需的特征
31
+ response = requests.post(LLM_API_URL + "/api/predict", json={"input": user_input})
32
+ llm_output = response.json().get("prediction", "")
33
+
34
+ # 解析 LLM 输出(示例解析)
35
+ year, period = 2025, 16
36
+ nums = [5, 12, 23, 34, 45, 56]
37
+ special = 7
38
+
39
+ # **📌 预测**
40
+ prediction = predict_lottery(year, period, *nums, special)
41
+
42
+ return f"预测的号码是: {prediction}\n\n模型解析的特征:{llm_output}"
43
+
44
  # **📌 预测函数**
45
  def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
46
  # 从历史数据查找对应的月份和日期
 
63
 
64
  # **📌 Gradio Web 界面**
65
  iface = gr.Interface(
66
+ fn=get_prediction_from_llm,
67
+ inputs=gr.Textbox(label="请输入问题或期号信息"),
 
 
 
 
 
68
  outputs="text",
69
  title="六合彩预测模型",
70
+ description="通过与 LLM 交互,解析输入信息并进行预测"
71
  )
72
 
73
  # **📌 启动 Gradio 应用**