Spaces:
Sleeping
Sleeping
Sarath Rajan Senthilkumar
commited on
Commit
•
e872ca4
1
Parent(s):
6a6ddea
Upload 2 files
Browse files- app.py +98 -0
- requirements.txt +85 -0
app.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import plotly.graph_objects as go
|
3 |
+
import gradio as gr
|
4 |
+
import schedule
|
5 |
+
import time
|
6 |
+
|
7 |
+
# Load the dataset
|
8 |
+
|
9 |
+
|
10 |
+
|
11 |
+
|
12 |
+
def fetch_dataset():
|
13 |
+
url = "https://docs.google.com/spreadsheets/d/1rSiT1pfqLKk4OT-VE2JQ1RCBZX5-TZEU8Slhr_Eqk5Q/export?format=csv"
|
14 |
+
dataset = pd.read_csv(url)
|
15 |
+
return dataset
|
16 |
+
|
17 |
+
def showRoutes(routes:list):
|
18 |
+
if "All Routes" in routes:
|
19 |
+
filtered_df = df
|
20 |
+
else:
|
21 |
+
filtered_df = df[(df['ROUTE_NO'].isin(routes))]
|
22 |
+
#print(filtered_df)
|
23 |
+
|
24 |
+
fig = go.Figure(go.Scattermapbox(
|
25 |
+
lat=filtered_df['LATITUDE'].tolist(),
|
26 |
+
lon=filtered_df['LONGITUDE'].tolist(),
|
27 |
+
mode='markers',
|
28 |
+
marker=go.scattermapbox.Marker(
|
29 |
+
size=6
|
30 |
+
),
|
31 |
+
hoverinfo="text",
|
32 |
+
hovertemplate='<b>ROUTE_NO</b>: %{text}<br><b>Stop_Name</b>: %{customdata}',
|
33 |
+
text=filtered_df['ROUTE_NO'].tolist(),
|
34 |
+
customdata=filtered_df['STOP_NAME'].tolist()
|
35 |
+
))
|
36 |
+
|
37 |
+
fig.update_layout(
|
38 |
+
mapbox_style="open-street-map",
|
39 |
+
hovermode='closest',
|
40 |
+
mapbox=dict(
|
41 |
+
bearing=0,
|
42 |
+
center=go.layout.mapbox.Center(
|
43 |
+
lat=12.99468,
|
44 |
+
lon=80.25892
|
45 |
+
),
|
46 |
+
pitch=0,
|
47 |
+
zoom=9
|
48 |
+
),
|
49 |
+
|
50 |
+
|
51 |
+
)
|
52 |
+
filtered_df2 = filtered_df[["ROUTE_NO","STOP_NAME","TIMING"]]
|
53 |
+
return fig,filtered_df2
|
54 |
+
|
55 |
+
df =fetch_dataset()
|
56 |
+
# Function to update dataset every 12 hours
|
57 |
+
def update_dataset():
|
58 |
+
global df
|
59 |
+
df = fetch_dataset()
|
60 |
+
|
61 |
+
# Schedule dataset update every 12 hours
|
62 |
+
schedule.every(12).hours.do(update_dataset)
|
63 |
+
|
64 |
+
# Function to continuously run scheduled tasks
|
65 |
+
def run_scheduler():
|
66 |
+
while True:
|
67 |
+
schedule.run_pending()
|
68 |
+
time.sleep(1)
|
69 |
+
|
70 |
+
|
71 |
+
|
72 |
+
def startGradio():
|
73 |
+
Routes=["All Routes"]
|
74 |
+
routes = df["ROUTE_NO"].unique().tolist()
|
75 |
+
Routes.extend(routes)
|
76 |
+
# Create the Gradio interface
|
77 |
+
with gr.Blocks() as demo:
|
78 |
+
with gr.Column():
|
79 |
+
text1 = gr.Text(value="College Bus Route Tracker",interactive=False,show_label=False)
|
80 |
+
routes = gr.CheckboxGroup(choices=Routes,label="Routes",value=["All Routes"])
|
81 |
+
|
82 |
+
map_component = gr.Plot(min_width=600)
|
83 |
+
table = gr.DataFrame(min_width=600)
|
84 |
+
#btn = gr.Button(value="Update Filter")
|
85 |
+
text2 = gr.Textbox(value="A app based on the research done by \n1.Sarath Rajan Senthilkumar \n2.Veer Jabak \n3.Gautham Vidyashankar \n4.Divij D\n5.Dr Srisakthi Saravanan",show_label=False,interactive=False)
|
86 |
+
|
87 |
+
#demo.load(fn=showRoutes,inputs=[routes],outputs=[map_component,table])
|
88 |
+
demo.load(fn=showRoutes,inputs=[routes],outputs=[map_component,table])
|
89 |
+
routes.change(fn=showRoutes,inputs=[routes],outputs=[map_component,table])
|
90 |
+
#btn.click(fn=showRoutes,inputs=[routes],outputs=[map_component,table])
|
91 |
+
|
92 |
+
demo.launch()
|
93 |
+
|
94 |
+
if __name__ == "__main__":
|
95 |
+
startGradio()
|
96 |
+
run_scheduler()
|
97 |
+
|
98 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,85 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
aiofiles==23.2.1
|
2 |
+
aiohttp==3.9.5
|
3 |
+
aiosignal==1.3.1
|
4 |
+
altair==5.3.0
|
5 |
+
annotated-types==0.7.0
|
6 |
+
anyio==4.4.0
|
7 |
+
attrs==23.2.0
|
8 |
+
certifi==2024.6.2
|
9 |
+
charset-normalizer==3.3.2
|
10 |
+
click==8.1.7
|
11 |
+
contourpy==1.2.1
|
12 |
+
cycler==0.12.1
|
13 |
+
dill==0.3.8
|
14 |
+
dnspython==2.6.1
|
15 |
+
email_validator==2.2.0
|
16 |
+
fastapi==0.111.0
|
17 |
+
fastapi-cli==0.0.4
|
18 |
+
ffmpy==0.3.2
|
19 |
+
filelock==3.15.4
|
20 |
+
fonttools==4.53.0
|
21 |
+
frozenlist==1.4.1
|
22 |
+
fsspec==2024.5.0
|
23 |
+
gradio==4.37.2
|
24 |
+
gradio_client==1.0.2
|
25 |
+
h11==0.14.0
|
26 |
+
httpcore==1.0.5
|
27 |
+
httptools==0.6.1
|
28 |
+
httpx==0.27.0
|
29 |
+
huggingface-hub==0.23.4
|
30 |
+
idna==3.7
|
31 |
+
importlib_resources==6.4.0
|
32 |
+
Jinja2==3.1.4
|
33 |
+
jsonschema==4.22.0
|
34 |
+
jsonschema-specifications==2023.12.1
|
35 |
+
kiwisolver==1.4.5
|
36 |
+
markdown-it-py==3.0.0
|
37 |
+
MarkupSafe==2.1.5
|
38 |
+
matplotlib==3.9.0
|
39 |
+
mdurl==0.1.2
|
40 |
+
multidict==6.0.5
|
41 |
+
multiprocess==0.70.16
|
42 |
+
numpy==2.0.0
|
43 |
+
orjson==3.10.5
|
44 |
+
packaging==24.1
|
45 |
+
pandas==2.2.2
|
46 |
+
pillow==10.3.0
|
47 |
+
plotly==5.22.0
|
48 |
+
pyarrow==16.1.0
|
49 |
+
pyarrow-hotfix==0.6
|
50 |
+
pydantic==2.7.4
|
51 |
+
pydantic_core==2.18.4
|
52 |
+
pydub==0.25.1
|
53 |
+
Pygments==2.18.0
|
54 |
+
pyparsing==3.1.2
|
55 |
+
python-dateutil==2.9.0.post0
|
56 |
+
python-dotenv==1.0.1
|
57 |
+
python-multipart==0.0.9
|
58 |
+
pytz==2024.1
|
59 |
+
PyYAML==6.0.1
|
60 |
+
referencing==0.35.1
|
61 |
+
requests==2.32.3
|
62 |
+
rich==13.7.1
|
63 |
+
rpds-py==0.18.1
|
64 |
+
ruff==0.5.0
|
65 |
+
schedule==1.2.2
|
66 |
+
semantic-version==2.10.0
|
67 |
+
shellingham==1.5.4
|
68 |
+
six==1.16.0
|
69 |
+
sniffio==1.3.1
|
70 |
+
starlette==0.37.2
|
71 |
+
tenacity==8.4.2
|
72 |
+
tomlkit==0.12.0
|
73 |
+
toolz==0.12.1
|
74 |
+
tqdm==4.66.4
|
75 |
+
typer==0.12.3
|
76 |
+
typing_extensions==4.12.2
|
77 |
+
tzdata==2024.1
|
78 |
+
ujson==5.10.0
|
79 |
+
urllib3==2.2.2
|
80 |
+
uvicorn==0.30.1
|
81 |
+
uvloop==0.19.0
|
82 |
+
watchfiles==0.22.0
|
83 |
+
websockets==11.0.3
|
84 |
+
xxhash==3.4.1
|
85 |
+
yarl==1.9.4
|