Spaces:
Runtime error
Runtime error
File size: 2,287 Bytes
6fedaa7 be9e9ca adcbaca 511f39b 6fedaa7 6cd6dff 6fedaa7 651d250 6fedaa7 c307f2e 6fedaa7 852d5ad be63a08 6fedaa7 03d8f37 b315b3e 03d8f37 bd7f540 03d8f37 bd7f540 03d8f37 f5086fc eba165f ec7f812 f5086fc eba165f ec7f812 f5086fc 03d8f37 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
import sklearn
import gradio as gr
import joblib
import pandas as pd
import datasets
import requests
import json
import dateutil.parser as dp
import pandas as pd
from huggingface_hub import hf_hub_url, cached_download
import time
import datetime
title = "Stockholm Highway E4 Real Time Traffic Prediction"
description = "Stockholm E4 (59°23'44.7"" N 17°59'00.4""E) highway real time traffic prediction, updated in every hour"
inputs = [gr.Dataframe(row_count = (1, "fixed"), col_count=(7,"fixed"), label="Input Data", interactive=1)]
outputs = [gr.Dataframe(row_count = (1, "fixed"), col_count=(1, "fixed"), label="Predictions", headers=["Congestion Level"])]
model = joblib.load("./traffic_model.pkl")
response_smhi = requests.get(
'https://opendata-download-metanalys.smhi.se/api/category/mesan1g/version/2/geotype/point/lon/17.983/lat/59.3957/data.json')
json_response_smhi = json.loads(response_smhi.text)
def infer(input_dataframe):
return pd.DataFrame(model.predict(input_dataframe))
referenceTime = dp.parse(json_response_smhi["referenceTime"]).timestamp()
def get_time():
return datetime.datetime.now()
#with gr.Blocks() as demo:
# with gr.Row():
# with gr.Column():
# c_time2 = gr.Textbox(label="Current Time refreshed every second")
# demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1)
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
gr.Dataframe(row_count = (1, "fixed"), col_count=(7,"fixed"),
headers=["referenceTime", "t", "ws", "prec1h", "fesn1h", "vis", "confidence"],
# datatype=["timestamp", "float", "float", "float", "float", "float"],
label="Input Data", interactive=1)
c_time2 = gr.Textbox(label="Current Time refreshed every second")
demo.load(lambda: datetime.datetime.now(), None, c_time2, every=1)
with gr.Column:
gr.Dataframe(row_count = (1, "fixed"), col_count=(1, "fixed"), label="Predictions", headers=["Congestion Level"])
with gr.Row():
btn_sub = gr.Button(value="Submit")
btn_sub.click(infer, inputs = inputs, outputs = outputs)
demo.queue().launch() |