maty0505 commited on
Commit
81bf60b
·
verified ·
1 Parent(s): c4b2b21

modified 2

Browse files
Files changed (2) hide show
  1. app.py +17 -20
  2. requiremets.txt +1 -2
app.py CHANGED
@@ -1,31 +1,28 @@
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.components.Textbox(label="Enter future date (YYYY-MM-DD)"),
28
- outputs=gr.components.Textbox(label="Predicted sales")
29
  )
30
 
31
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ import matplotlib.pyplot as plt
3
  import pandas as pd
 
 
4
 
5
+ # サンプルデータ
6
+ data = {
7
+ '年月': ['2023-01', '2023-02', '2023-03', '2023-04', '2023-05', '2023-06'],
8
+ '乗客数': [1200, 1500, 1700, 1600, 1800, 2000]
9
+ }
10
 
11
+ df = pd.DataFrame(data)
 
 
 
 
 
12
 
13
+ def plot_passenger_trends():
14
+ fig, ax = plt.subplots()
15
+ ax.plot(df['年月'], df['乗客数'], marker='o')
16
+ ax.set_title('JRの乗客数の推移')
17
+ ax.set_xlabel('年月')
18
+ ax.set_ylabel('乗客数 (千人)')
19
+ return fig
20
 
21
  # Gradioインターフェースの定義
22
  iface = gr.Interface(
23
+ fn=plot_passenger_trends,
24
+ inputs=[],
25
+ outputs=gr.components.Plot(label="JRの乗客数の推移")
26
  )
27
 
28
  if __name__ == "__main__":
requiremets.txt CHANGED
@@ -1,5 +1,4 @@
1
  gradio
 
2
  pandas
3
- scikit-learn
4
- numpy
5
 
 
1
  gradio
2
+ matplotlib
3
  pandas
 
 
4