Update app.py
Browse files
app.py
CHANGED
@@ -6,6 +6,9 @@ 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` 进行数据处理...")
|
@@ -24,22 +27,32 @@ 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 |
-
|
31 |
-
|
32 |
-
|
33 |
|
34 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
43 |
|
44 |
# **📌 预测函数**
|
45 |
def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
|
|
|
6 |
import requests
|
7 |
from huggingface_hub import hf_hub_download
|
8 |
|
9 |
+
# **📌 LLM 服务器地址(修改为你的 LLM Space 地址)**
|
10 |
+
LLM_API_URL = "https://your-llm-space.gradio.app" # 替换为 LLM 服务器地址
|
11 |
+
|
12 |
# **📌 先运行 `preprocess.py` 处理数据**
|
13 |
if not os.path.exists("processed_data.csv"):
|
14 |
print("📌 运行 `preprocess.py` 进行数据处理...")
|
|
|
27 |
model.load_model(model_path)
|
28 |
|
29 |
# **📌 调用 LLM API 解析用户输入**
|
|
|
|
|
30 |
def get_prediction_from_llm(user_input):
|
31 |
+
try:
|
32 |
+
# 发送请求到 LLM API
|
33 |
+
response = requests.post(LLM_API_URL + "/api/predict", json={"input": user_input})
|
34 |
|
35 |
+
# **确保返回 JSON**
|
36 |
+
if response.status_code == 200:
|
37 |
+
try:
|
38 |
+
llm_output = response.json().get("prediction", "")
|
39 |
+
except requests.exceptions.JSONDecodeError:
|
40 |
+
return "❌ LLM 服务器返回了无效的 JSON 数据,请检查 LLM Space 是否正常运行。"
|
41 |
+
else:
|
42 |
+
return f"❌ LLM 服务器错误,状态码: {response.status_code}"
|
43 |
+
|
44 |
+
except requests.exceptions.ConnectionError:
|
45 |
+
return "❌ 无法连接到 LLM 服务器,请确保 LLM Space 正在运行。"
|
46 |
+
|
47 |
+
# **📌 解析 LLM 输出**
|
48 |
year, period = 2025, 16
|
49 |
nums = [5, 12, 23, 34, 45, 56]
|
50 |
special = 7
|
51 |
|
52 |
+
# **📌 进行 XGBoost 预测**
|
53 |
prediction = predict_lottery(year, period, *nums, special)
|
54 |
+
|
55 |
+
return f"📊 预测的号码是: {prediction}\n\n📢 LLM 解析的特征:{llm_output}"
|
56 |
|
57 |
# **📌 预测函数**
|
58 |
def predict_lottery(year, period, num1, num2, num3, num4, num5, num6, special):
|