YDluffy commited on
Commit
504033c
·
verified ·
1 Parent(s): 7d1dc30

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -18
app.py CHANGED
@@ -1,4 +1,3 @@
1
- import openai
2
  import gradio as gr
3
  import xgboost as xgb
4
  import numpy as np
@@ -7,9 +6,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()
@@ -24,26 +20,25 @@ def predict_lottery(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返回了这些数字
@@ -59,7 +54,7 @@ iface = gr.Interface(
59
  inputs=gr.Textbox(label="请输入问题或期号信息"),
60
  outputs="text",
61
  title="六合彩预测模型",
62
- description="通过与大语言模型(GPT-4)对话,预测指定期号的开奖号码,并根据反馈优化模型"
63
  )
64
 
65
  iface.launch(share=True)
 
 
1
  import gradio as gr
2
  import xgboost as xgb
3
  import numpy as np
 
6
  import pandas as pd
7
  from transformers import pipeline
8
 
 
 
 
9
  # 加载 XGBoost 模型
10
  model_path = hf_hub_download(repo_id="YDluffy/lottery_prediction", filename="lottery_xgboost_model.json")
11
  model = xgb.XGBRegressor()
 
20
  prediction = model.predict(features)
21
  return prediction
22
 
23
+ # 加载 Hugging Face GPT-Neo 模型
24
+ generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')
25
+
26
+ # 生成文本的函数
27
+ def generate_text(user_input):
28
+ # 使用模型生成文本
29
+ output = generator(user_input, max_length=100, num_return_sequences=1)
30
+ return output[0]['generated_text']
 
31
 
32
  # 通过 GPT-4 提取输入特征并调用 XGBoost 模型进行预测
33
  def predict_and_interact(user_input):
34
  # 使用 GPT-4 提取必要信息(例如期号、历史号码等)
35
  prompt = f"请从以下问题中提取出预测数字所需的参数:'{user_input}'"
 
36
 
37
+ # 通过 GPT-Neo 生成文本
38
+ gpt_response = generate_text(prompt)
 
39
 
40
+ # 假设 GPT-4 提取了这些特征
41
+ # 在此阶段,我们可以从 GPT-Neo 的响应中提取参数,并将其传递给 XGBoost 模型
42
  # 示例:假设 GPT-4 提取了这些特征
43
  year, period = 2025, 16 # 从对话提取的特征(例如:2025年第16期)
44
  nums = [5, 12, 23, 34, 45, 56] # 假设GPT返回了这些数字
 
54
  inputs=gr.Textbox(label="请输入问题或期号信息"),
55
  outputs="text",
56
  title="六合彩预测模型",
57
+ description="通过与大语言模型(GPT-Neo)对话,预测指定期号的开奖号码,并根据反馈优化模型"
58
  )
59
 
60
  iface.launch(share=True)