Spaces:
Runtime error
Runtime error
William_S
commited on
Commit
•
c72284d
1
Parent(s):
9ae8c4e
make interface more user-friendly
Browse files- app.py +25 -11
- requirements.txt +2 -0
app.py
CHANGED
@@ -5,11 +5,19 @@ from PIL import Image
|
|
5 |
import requests
|
6 |
from tensorflow import keras
|
7 |
|
|
|
|
|
|
|
8 |
import hopsworks
|
9 |
|
|
|
|
|
|
|
10 |
MODEL_NAME = "earthquake_model"
|
11 |
MODEL_VERSION = 1
|
12 |
|
|
|
|
|
13 |
hw = hopsworks.login()
|
14 |
|
15 |
registry = hw.get_model_registry()
|
@@ -17,29 +25,35 @@ model = registry.get_model(MODEL_NAME, version=MODEL_VERSION)
|
|
17 |
model_dir = model.download()
|
18 |
model = keras.models.load_model(os.path.join(model_dir, MODEL_NAME + ".h5"))
|
19 |
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
-
def earthquake(latitude, longitude, time):
|
22 |
input_list = []
|
23 |
-
input_list.append(latitude)
|
24 |
-
input_list.append(longitude)
|
25 |
-
input_list.append(
|
26 |
# prediction result of the model
|
27 |
res = model.predict(np.asarray(input_list).reshape(1, -1))[0]
|
28 |
# split the result to 2 separate variables
|
29 |
print(res)
|
30 |
-
return res[0]
|
31 |
|
32 |
demo = gr.Interface(
|
33 |
fn=earthquake,
|
34 |
-
title=
|
35 |
-
description=
|
36 |
allow_flagging="never",
|
37 |
inputs=[
|
38 |
-
gr.inputs.
|
39 |
-
gr.inputs.
|
40 |
-
gr.inputs.Number(default=167.2185429275, label="time"),
|
41 |
],
|
42 |
-
outputs=[
|
|
|
|
|
|
|
43 |
)
|
44 |
demo.launch()
|
45 |
|
|
|
5 |
import requests
|
6 |
from tensorflow import keras
|
7 |
|
8 |
+
from geopy.geocoders import Nominatim
|
9 |
+
from datetime import datetime
|
10 |
+
|
11 |
import hopsworks
|
12 |
|
13 |
+
GUI_TITLE = "Earthquake Predictive Analytics"
|
14 |
+
GUI_DESCRIPTION = "Experiment with location and time to predict depth and magnitude."
|
15 |
+
|
16 |
MODEL_NAME = "earthquake_model"
|
17 |
MODEL_VERSION = 1
|
18 |
|
19 |
+
TIME_FORMAT = "%Y-%m-%d %H:%M:%S"
|
20 |
+
|
21 |
hw = hopsworks.login()
|
22 |
|
23 |
registry = hw.get_model_registry()
|
|
|
25 |
model_dir = model.download()
|
26 |
model = keras.models.load_model(os.path.join(model_dir, MODEL_NAME + ".h5"))
|
27 |
|
28 |
+
geolocator = Nominatim(user_agent=GUI_TITLE)
|
29 |
+
|
30 |
+
def earthquake(location, time):
|
31 |
+
geodata = geolocator.geocode(location)
|
32 |
+
time_input = datetime.strptime(time, TIME_FORMAT).timestamp() / 1E7
|
33 |
|
|
|
34 |
input_list = []
|
35 |
+
input_list.append(geodata.latitude)
|
36 |
+
input_list.append(geodata.longitude)
|
37 |
+
input_list.append(time_input)
|
38 |
# prediction result of the model
|
39 |
res = model.predict(np.asarray(input_list).reshape(1, -1))[0]
|
40 |
# split the result to 2 separate variables
|
41 |
print(res)
|
42 |
+
return geodata.address, res[0]
|
43 |
|
44 |
demo = gr.Interface(
|
45 |
fn=earthquake,
|
46 |
+
title=GUI_TITLE,
|
47 |
+
description=GUI_DESCRIPTION,
|
48 |
allow_flagging="never",
|
49 |
inputs=[
|
50 |
+
gr.inputs.Textbox(value="Stockholm", label="location"),
|
51 |
+
gr.inputs.Textbox(default=datetime.now().strftime(TIME_FORMAT), label="time"),
|
|
|
52 |
],
|
53 |
+
outputs=[
|
54 |
+
gr.Textbox(label="full location"),
|
55 |
+
gr.Number(label="magnitude"),
|
56 |
+
]
|
57 |
)
|
58 |
demo.launch()
|
59 |
|
requirements.txt
CHANGED
@@ -1,2 +1,4 @@
|
|
1 |
hopsworks
|
2 |
tensorflow
|
|
|
|
|
|
1 |
hopsworks
|
2 |
tensorflow
|
3 |
+
geopy
|
4 |
+
Nominatim
|