Update evtracker.py
Browse files- evtracker.py +4 -9
evtracker.py
CHANGED
|
@@ -1,8 +1,7 @@
|
|
| 1 |
import pandas as pd
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
-
# 1. The Database (
|
| 5 |
-
# We can connect this to a live web scraper later.
|
| 6 |
ev_data = {
|
| 7 |
"Model": ["Bounce Infinity E1", "TVS iQube", "Bajaj Chetak", "Ather 450X", "Ola S1 Pro", "Hero Vida V1"],
|
| 8 |
"Price (INR)": [79000, 123000, 122000, 138000, 147000, 145000],
|
|
@@ -10,7 +9,7 @@ ev_data = {
|
|
| 10 |
"Top Speed (kmph)": [65, 78, 73, 90, 120, 80],
|
| 11 |
"Charging Time (Hrs)": [4.0, 4.5, 4.0, 5.5, 6.5, 6.0]
|
| 12 |
}
|
| 13 |
-
df = pd.
|
| 14 |
|
| 15 |
# 2. The Search Logic
|
| 16 |
def recommend_ev(max_budget, min_range):
|
|
@@ -20,13 +19,10 @@ def recommend_ev(max_budget, min_range):
|
|
| 20 |
# Sort the results so the cheapest options appear at the top
|
| 21 |
filtered_df = filtered_df.sort_values(by="Price (INR)")
|
| 22 |
|
| 23 |
-
# Return the clean dataframe
|
| 24 |
return filtered_df
|
| 25 |
|
| 26 |
# 3. The Frontend Architecture
|
| 27 |
-
# We use Gradio Blocks to make it look like a modern, enterprise dashboard
|
| 28 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
| 29 |
-
|
| 30 |
gr.Markdown("# 🛵 Smart EV Tracker & Recommender")
|
| 31 |
gr.Markdown("Filter the current electric two-wheeler market based on your exact constraints.")
|
| 32 |
|
|
@@ -34,7 +30,6 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 34 |
# Left Column: User Controls
|
| 35 |
with gr.Column(scale=1):
|
| 36 |
gr.Markdown("### Search Filters")
|
| 37 |
-
# Defaulting to 60k to match typical entry-level EV searches
|
| 38 |
budget_slider = gr.Slider(minimum=50000, maximum=160000, step=5000, value=90000, label="Maximum Budget (₹)")
|
| 39 |
range_slider = gr.Slider(minimum=50, maximum=150, step=5, value=75, label="Minimum Range Required (km)")
|
| 40 |
search_btn = gr.Button("Find My EV", variant="primary")
|
|
@@ -42,11 +37,11 @@ with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
| 42 |
# Right Column: Data Output
|
| 43 |
with gr.Column(scale=2):
|
| 44 |
gr.Markdown("### Recommended Models")
|
| 45 |
-
# Gradio automatically renders Pandas Dataframes as beautiful, interactive tables
|
| 46 |
output_table = gr.Dataframe(headers=["Model", "Price (INR)", "Real Range (km)", "Top Speed (kmph)", "Charging Time (Hrs)"])
|
| 47 |
|
| 48 |
# Wire the button to the logic function
|
| 49 |
search_btn.click(fn=recommend_ev, inputs=[budget_slider, range_slider], outputs=output_table)
|
| 50 |
|
| 51 |
# Launch the app
|
| 52 |
-
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# 1. The Database (Hardcoded directly, no CSV needed!)
|
|
|
|
| 5 |
ev_data = {
|
| 6 |
"Model": ["Bounce Infinity E1", "TVS iQube", "Bajaj Chetak", "Ather 450X", "Ola S1 Pro", "Hero Vida V1"],
|
| 7 |
"Price (INR)": [79000, 123000, 122000, 138000, 147000, 145000],
|
|
|
|
| 9 |
"Top Speed (kmph)": [65, 78, 73, 90, 120, 80],
|
| 10 |
"Charging Time (Hrs)": [4.0, 4.5, 4.0, 5.5, 6.5, 6.0]
|
| 11 |
}
|
| 12 |
+
df = pd.DataFrame(ev_data)
|
| 13 |
|
| 14 |
# 2. The Search Logic
|
| 15 |
def recommend_ev(max_budget, min_range):
|
|
|
|
| 19 |
# Sort the results so the cheapest options appear at the top
|
| 20 |
filtered_df = filtered_df.sort_values(by="Price (INR)")
|
| 21 |
|
|
|
|
| 22 |
return filtered_df
|
| 23 |
|
| 24 |
# 3. The Frontend Architecture
|
|
|
|
| 25 |
with gr.Blocks(theme=gr.themes.Soft()) as app:
|
|
|
|
| 26 |
gr.Markdown("# 🛵 Smart EV Tracker & Recommender")
|
| 27 |
gr.Markdown("Filter the current electric two-wheeler market based on your exact constraints.")
|
| 28 |
|
|
|
|
| 30 |
# Left Column: User Controls
|
| 31 |
with gr.Column(scale=1):
|
| 32 |
gr.Markdown("### Search Filters")
|
|
|
|
| 33 |
budget_slider = gr.Slider(minimum=50000, maximum=160000, step=5000, value=90000, label="Maximum Budget (₹)")
|
| 34 |
range_slider = gr.Slider(minimum=50, maximum=150, step=5, value=75, label="Minimum Range Required (km)")
|
| 35 |
search_btn = gr.Button("Find My EV", variant="primary")
|
|
|
|
| 37 |
# Right Column: Data Output
|
| 38 |
with gr.Column(scale=2):
|
| 39 |
gr.Markdown("### Recommended Models")
|
|
|
|
| 40 |
output_table = gr.Dataframe(headers=["Model", "Price (INR)", "Real Range (km)", "Top Speed (kmph)", "Charging Time (Hrs)"])
|
| 41 |
|
| 42 |
# Wire the button to the logic function
|
| 43 |
search_btn.click(fn=recommend_ev, inputs=[budget_slider, range_slider], outputs=output_table)
|
| 44 |
|
| 45 |
# Launch the app
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
app.launch()
|