White74195 commited on
Commit
6bd7867
·
1 Parent(s): c2f9b63

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import numpy as np
4
+ from sklearn.ensemble import RandomForestClassifier
5
+
6
+ # 示例:加载模型(这里用随机森林作为示例)
7
+ def load_model():
8
+ # 这里可以替换为你的模型加载逻辑
9
+ model = RandomForestClassifier()
10
+ # 假设我们有一些示例数据
11
+ X = np.array([[1, 2], [3, 4], [5, 6]])
12
+ y = np.array([0, 1, 0])
13
+ model.fit(X, y)
14
+ return model
15
+
16
+ model = load_model()
17
+
18
+ # 定义预测函数
19
+ def predict(price, sales, shop_rating):
20
+ # 将输入转换为模型需要的格式
21
+ input_data = np.array([[price, sales, shop_rating]])
22
+ prediction = model.predict(input_data)
23
+ return "爆款潜力高" if prediction[0] == 1 else "爆款潜力低"
24
+
25
+ # 创建 Gradio 界面
26
+ interface = gr.Interface(
27
+ fn=predict,
28
+ inputs=[
29
+ gr.Number(label="价格"),
30
+ gr.Number(label="销量"),
31
+ gr.Number(label="店铺评分"),
32
+ ],
33
+ outputs=gr.Textbox(label="预测结果"),
34
+ title="爆款商品预测",
35
+ description="输入商品的价格、销量和店铺评分,预测是否有爆款潜力。",
36
+ )
37
+
38
+ # 启动应用
39
+ interface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ gradio
2
+ numpy
3
+ pandas
4
+ scikit-learn