SevenhuijsenM commited on
Commit
be959b3
·
1 Parent(s): 3829ec7

fixed radio buttons

Browse files
Files changed (1) hide show
  1. app.py +45 -5
app.py CHANGED
@@ -23,11 +23,51 @@ print("Model downloaded")
23
 
24
 
25
  def predict(magnitudeOfDelay, hour, iconCategory, latitude, longitude, month):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # Create a row from the input
27
  row = {
28
- 'magnitudeOfDelay': magnitudeOfDelay,
29
- 'hour': hour,
30
- 'iconCategory': iconCategory,
31
  'latitude': latitude,
32
  'longitude': longitude,
33
  'month': month
@@ -57,9 +97,9 @@ demo = gr.Interface(
57
  description="Predicts the duration of a traffic incident in Stockholm",
58
  allow_flagging="never",
59
  inputs=[
60
- gr.inputs.Slider(0, 60, label="Magnitude of Delay"),
61
  gr.inputs.Slider(0, 23, label="Hour"),
62
- gr.inputs.Radio(["Accident", "Construction", "Congestion", "Disabled Vehicle", "Mass Transit", "Miscellaneous", "Other News", "Planned Event", "Road Hazard", "Roadwork", "Traffic Flow", "Weather"], label="Icon Category"),
63
  gr.inputs.Slider(59.25, 59.40, label="Latitude"),
64
  gr.inputs.Slider(18.00, 18.16, label="Longitude"),
65
  gr.inputs.Slider(1, 12, label="Month")
 
23
 
24
 
25
  def predict(magnitudeOfDelay, hour, iconCategory, latitude, longitude, month):
26
+ # Change the magnitude delay to an integer based on the index
27
+ if magnitudeOfDelay == 'Unknown':
28
+ magnitudeOfDelay = 0
29
+ elif magnitudeOfDelay == 'Minor':
30
+ magnitudeOfDelay = 1
31
+ elif magnitudeOfDelay == 'Moderate':
32
+ magnitudeOfDelay = 2
33
+ elif magnitudeOfDelay == 'Major':
34
+ magnitudeOfDelay = 3
35
+ elif magnitudeOfDelay == 'Undefined':
36
+ magnitudeOfDelay = 4
37
+
38
+ # Change the icon category to an integer based on the index
39
+ if iconCategory == 'Unknown':
40
+ iconCategory = 0
41
+ elif iconCategory == 'Accident':
42
+ iconCategory = 1
43
+ elif iconCategory == 'Fog':
44
+ iconCategory = 2
45
+ elif iconCategory == 'Dangerous Conditions':
46
+ iconCategory = 3
47
+ elif iconCategory == 'Rain':
48
+ iconCategory = 4
49
+ elif iconCategory == 'Ice':
50
+ iconCategory = 5
51
+ elif iconCategory == 'Jam':
52
+ iconCategory = 6
53
+ elif iconCategory == 'Lane Closed':
54
+ iconCategory = 7
55
+ elif iconCategory == 'Road Closed':
56
+ iconCategory = 8
57
+ elif iconCategory == 'Road Works':
58
+ iconCategory = 9
59
+ elif iconCategory == 'Wind':
60
+ iconCategory = 10
61
+ elif iconCategory == 'Flooding':
62
+ iconCategory = 11
63
+ elif iconCategory == 'Broken Down Vehicle':
64
+ iconCategory = 14
65
+
66
  # Create a row from the input
67
  row = {
68
+ 'magnitudeOfDelay': int(magnitudeOfDelay),
69
+ 'hour': int(hour),
70
+ 'iconCategory': int(iconCategory),
71
  'latitude': latitude,
72
  'longitude': longitude,
73
  'month': month
 
97
  description="Predicts the duration of a traffic incident in Stockholm",
98
  allow_flagging="never",
99
  inputs=[
100
+ gr.inputs.Radio(["Unknown", "Minor", "Moderate", "Major", "Undefined"]),
101
  gr.inputs.Slider(0, 23, label="Hour"),
102
+ gr.inputs.Radio(["Unknown", "Accident", "Fog", "Dangerous Conditions", "Rain", "Ice", "Jam", "Lane Closed", "Road Closed", "Road Works", "Wind", "Flooding", "Broken Down Vehicle"], label="Icon Category"),
103
  gr.inputs.Slider(59.25, 59.40, label="Latitude"),
104
  gr.inputs.Slider(18.00, 18.16, label="Longitude"),
105
  gr.inputs.Slider(1, 12, label="Month")