Spaces:
Sleeping
Sleeping
import gradio as gr | |
import pandas as pd | |
import numpy as np | |
from sklearn.ensemble import RandomForestClassifier | |
# 示例:加载模型(这里用随机森林作为示例) | |
def load_model(): | |
# 这里可以替换为你的模型加载逻辑 | |
model = RandomForestClassifier() | |
# 假设我们有一些示例数据 | |
X = np.array([[1, 2], [3, 4], [5, 6]]) | |
y = np.array([0, 1, 0]) | |
model.fit(X, y) | |
return model | |
model = load_model() | |
# 定义预测函数 | |
def predict(price, sales, shop_rating): | |
# 将输入转换为模型需要的格式 | |
input_data = np.array([[price, sales, shop_rating]]) | |
prediction = model.predict(input_data) | |
return "爆款潜力高" if prediction[0] == 1 else "爆款潜力低" | |
# 创建 Gradio 界面 | |
interface = gr.Interface( | |
fn=predict, | |
inputs=[ | |
gr.Number(label="价格"), | |
gr.Number(label="销量"), | |
gr.Number(label="店铺评分"), | |
], | |
outputs=gr.Textbox(label="预测结果"), | |
title="爆款商品预测", | |
description="输入商品的价格、销量和店铺评分,预测是否有爆款潜力。", | |
) | |
# 启动应用 | |
interface.launch() |