maty0505 commited on
Commit
28745e6
·
verified ·
1 Parent(s): 734b83f

upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +33 -0
  2. requiremets.txt +5 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from sklearn.linear_model import LinearRegression
4
+ import numpy as np
5
+
6
+ # サンプルデータの作成
7
+ np.random.seed(0)
8
+ dates = pd.date_range('20230101', periods=100)
9
+ sales = np.random.randint(100, 200, size=(100,))
10
+ data = pd.DataFrame({'date': dates, 'sales': sales})
11
+
12
+ # モデルの訓練
13
+ model = LinearRegression()
14
+ data['date_ordinal'] = pd.to_datetime(data['date']).map(pd.Timestamp.toordinal)
15
+ X = data['date_ordinal'].values.reshape(-1, 1)
16
+ y = data['sales'].values
17
+ model.fit(X, y)
18
+
19
+ def predict_sales(future_date):
20
+ future_date_ordinal = pd.to_datetime(future_date).toordinal()
21
+ prediction = model.predict(np.array([[future_date_ordinal]]))
22
+ return prediction[0]
23
+
24
+ # Gradioインターフェースの定義
25
+ iface = gr.Interface(
26
+ fn=predict_sales,
27
+ inputs=gr.inputs.Textbox(label="Enter future date (YYYY-MM-DD)"),
28
+ outputs=gr.outputs.Textbox(label="Predicted sales")
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ iface.launch()
33
+
requiremets.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio
2
+ pandas
3
+ scikit-learn
4
+ numpy
5
+