YDluffy commited on
Commit
8898ec4
·
verified ·
1 Parent(s): ebcc7d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -13
app.py CHANGED
@@ -1,32 +1,65 @@
 
1
  import gradio as gr
2
- import joblib
3
- from huggingface_hub import hf_hub_download
4
  import xgboost as xgb
5
  import numpy as np
 
 
 
 
6
 
7
- # Hugging Face 下载模型
 
 
 
8
  model_path = hf_hub_download(repo_id="YDluffy/lottery_prediction", filename="lottery_xgboost_model.json")
9
  model = xgb.XGBRegressor()
10
  model.load_model(model_path)
11
 
 
 
 
12
  # 预测函数
13
  def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
14
  features = np.array([[year, period, num1, num2, num3, num4, num5, num6, special]])
15
  prediction = model.predict(features)
16
  return prediction
17
 
18
- # 创建 Gradio Web 界面
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  iface = gr.Interface(
20
- fn=predict_lottery,
21
- inputs=[
22
- gr.Number(label="年份"), gr.Number(label="期数"),
23
- gr.Number(label="号码1"), gr.Number(label="号码2"), gr.Number(label="号码3"),
24
- gr.Number(label="号码4"), gr.Number(label="号码5"), gr.Number(label="号码6"),
25
- gr.Number(label="特别号码")
26
- ],
27
  outputs="text",
28
  title="六合彩预测模型",
29
- description="输入期号和历史开奖号码,预测下一期开奖"
30
  )
31
 
32
- iface.launch()
 
1
+ import openai
2
  import gradio as gr
 
 
3
  import xgboost as xgb
4
  import numpy as np
5
+ import joblib
6
+ from huggingface_hub import hf_hub_download
7
+ import pandas as pd
8
+ from transformers import pipeline
9
 
10
+ # 设置 OpenAI API 密钥
11
+ openai.api_key = "your-openai-api-key" # 使用你的 OpenAI API 密钥
12
+
13
+ # 加载 XGBoost 模型
14
  model_path = hf_hub_download(repo_id="YDluffy/lottery_prediction", filename="lottery_xgboost_model.json")
15
  model = xgb.XGBRegressor()
16
  model.load_model(model_path)
17
 
18
+ # 加载历史数据
19
+ df = pd.read_csv("cleaned_mark_six.csv") # 或者加载历史数据文件
20
+
21
  # 预测函数
22
  def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
23
  features = np.array([[year, period, num1, num2, num3, num4, num5, num6, special]])
24
  prediction = model.predict(features)
25
  return prediction
26
 
27
+ # GPT-4 对话函数
28
+ def chat_with_gpt(user_input):
29
+ # 调用 GPT-4 生成对话
30
+ response = openai.Completion.create(
31
+ model="gpt-4", # 使用 GPT-4 模型
32
+ prompt=user_input,
33
+ max_tokens=150
34
+ )
35
+ return response.choices[0].text.strip()
36
+
37
+ # 通过 GPT-4 提取输入特征并调用 XGBoost 模型进行预测
38
+ def predict_and_interact(user_input):
39
+ # 使用 GPT-4 提取必要信息(例如期号、历史号码等)
40
+ prompt = f"请从以下问题中提取出预测数字所需的参数:'{user_input}'"
41
+ gpt_response = chat_with_gpt(prompt)
42
+
43
+ # 假设 GPT-4 已经正确提取并返回了需要的特征
44
+ # 在此阶段,我们可以从 GPT-4 的响应中提取参数,并将其传递给 XGBoost 模型
45
+ # 假设 GPT-4 提取的特征已经是格式化后的参数(年份、期号、号码)
46
+
47
+ # 示例:假设 GPT-4 提取了这些特征
48
+ year, period = 2025, 16 # 从对话提取的特征(例如:2025年第16期)
49
+ nums = [5, 12, 23, 34, 45, 56] # 假设GPT返回了这些数字
50
+ special = 7 # 假设GPT返回了特别号码
51
+
52
+ # 调用 XGBoost 模型进行预测
53
+ prediction = predict_lottery(year, period, *nums, special)
54
+ return f"预测的号码是: {prediction}"
55
+
56
+ # Gradio Web 界面
57
  iface = gr.Interface(
58
+ fn=predict_and_interact,
59
+ inputs=gr.Textbox(label="请输入问题或期号信息"),
 
 
 
 
 
60
  outputs="text",
61
  title="六合彩预测模型",
62
+ description="通过与大语言模型(GPT-4)对话,预测指定期号的开奖号码,并根据反馈优化模型"
63
  )
64
 
65
+ iface.launch(share=True)