Spaces:
Sleeping
Sleeping
Commit
·
2d7601f
1
Parent(s):
1020440
Upload 2 files
Browse files- app.py +66 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from PIL import Image
|
3 |
+
import requests
|
4 |
+
import hopsworks
|
5 |
+
import joblib
|
6 |
+
import pandas as pd
|
7 |
+
import numpy as np
|
8 |
+
|
9 |
+
project = hopsworks.login(project='suyiw000')
|
10 |
+
|
11 |
+
fs = project.get_feature_store()
|
12 |
+
|
13 |
+
|
14 |
+
mf = project.get_model_registry()
|
15 |
+
model = mf.get_model("food_model", version=1)
|
16 |
+
model_dir = model.download()
|
17 |
+
model = joblib.load(model_dir + "/food_model.pkl")
|
18 |
+
print("Model downloaded")
|
19 |
+
|
20 |
+
|
21 |
+
market = ['Badakhshan', 'Badghis', 'Baghlan', 'Balkh', 'Bamyan', 'Daykundi', 'Farah', 'Faryab', 'Ghazni', 'Ghor', 'Hilmand', 'Hirat', 'Jawzjan' 'Kabul', 'Kandahar', 'Kapisa', 'Khost', 'Kunar', 'Kunduz', 'Laghman', 'Logar', 'Maidan Wardak', 'Nangarhar', 'Nimroz', 'Nuristan', 'Paktika', 'Paktya', 'Panjsher', 'Parwan', 'Samangan', 'Sar-e-Pul', 'Takhar', 'Uruzgan', 'Zabul']
|
22 |
+
commodity = ['Bread', 'Oil_cooking', 'Pulses', 'Rice_high', 'Rice_low', 'Salt', 'Sugar', 'Wheat', 'Wheatflour_high', 'Wheatflour_low']
|
23 |
+
|
24 |
+
|
25 |
+
def predict_price(year, month, market, food):
|
26 |
+
market_empty = np.zeros(34)
|
27 |
+
market_name = ['Badakhshan', 'Badghis', 'Baghlan', 'Balkh', 'Bamyan', 'Daykundi', 'Farah', 'Faryab', 'Ghazni', 'Ghor', 'Hilmand', 'Hirat', 'Jawzjan' 'Kabul', 'Kandahar', 'Kapisa', 'Khost', 'Kunar', 'Kunduz', 'Laghman', 'Logar', 'Maidan Wardak', 'Nangarhar', 'Nimroz', 'Nuristan', 'Paktika', 'Paktya', 'Panjsher', 'Parwan', 'Samangan', 'Sar-e-Pul', 'Takhar', 'Uruzgan', 'Zabul']
|
28 |
+
market = []
|
29 |
+
for i in range(34):
|
30 |
+
temp_market = market_empty.copy()
|
31 |
+
temp_market[i] = 1.0
|
32 |
+
market.append(temp_market)
|
33 |
+
|
34 |
+
commodity_empty = np.zeros(10)
|
35 |
+
commodity_name = ['Bread', 'Oil_cooking', 'Pulses', 'Rice_high', 'Rice_low', 'Salt', 'Sugar', 'Wheat', 'Wheatflour_high', 'Wheatflour_low']
|
36 |
+
commodity=[]
|
37 |
+
for i in range(10):
|
38 |
+
commodity_array = commodity_empty.copy()
|
39 |
+
commodity_array[i] = 1.0
|
40 |
+
commodity.append(commodity_array)
|
41 |
+
|
42 |
+
commodity_with_names = dict(zip(commodity_name, commodity))
|
43 |
+
arrays_with_names = dict(zip(market_name, market))
|
44 |
+
|
45 |
+
date = ((year*10000+month*100+15)-20200000)/100000
|
46 |
+
|
47 |
+
input_data = np.concatenate([arrays_with_names[market], commodity_with_names[food], [date]]).reshape(1, -1)
|
48 |
+
|
49 |
+
prediction = model.predict(input_data)
|
50 |
+
|
51 |
+
return prediction
|
52 |
+
|
53 |
+
|
54 |
+
demo = gr.Interface(
|
55 |
+
fn = predict_price,
|
56 |
+
title = "AFG FOOD PRICE PREDICTION",
|
57 |
+
allow_flagging="never",
|
58 |
+
inputs=[
|
59 |
+
gr.Number(label="Year"),
|
60 |
+
gr.Number(label="Mouth"),
|
61 |
+
gr.Dropdown(choices=market, label="Market"),
|
62 |
+
gr.Dropdown(choices=commodity, label="Food Type")
|
63 |
+
],
|
64 |
+
outputs="text"
|
65 |
+
)
|
66 |
+
demo.launch(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
hopsworks
|
2 |
+
joblib
|
3 |
+
scikit-learn
|