evtracker / app.py
BalajiM's picture
Upload app.py
d6bb049 verified
import pandas as pd
import gradio as gr
# 1. The Database (V1 Mock Data for Madurai Market)
# We can connect this to a live web scraper later.
ev_data = {
"Model": ["Bounce Infinity E1", "TVS iQube", "Bajaj Chetak", "Ather 450X", "Ola S1 Pro", "Hero Vida V1"],
"Price (INR)": [79000, 123000, 122000, 138000, 147000, 145000],
"Real Range (km)": [85, 100, 90, 105, 143, 110],
"Top Speed (kmph)": [65, 78, 73, 90, 120, 80],
"Charging Time (Hrs)": [4.0, 4.5, 4.0, 5.5, 6.5, 6.0]
}
df = pd.DataFrame(ev_data)
# 2. The Search Logic
def recommend_ev(max_budget, min_range):
# Filter the dataframe based on user slider inputs
filtered_df = df[(df["Price (INR)"] <= max_budget) & (df["Real Range (km)"] >= min_range)]
# Sort the results so the cheapest options appear at the top
filtered_df = filtered_df.sort_values(by="Price (INR)")
# Return the clean dataframe
return filtered_df
# 3. The Frontend Architecture
# We use Gradio Blocks to make it look like a modern, enterprise dashboard
with gr.Blocks(theme=gr.themes.Soft()) as app:
gr.Markdown("# 🛵 Smart EV Tracker & Recommender")
gr.Markdown("Filter the current electric two-wheeler market based on your exact constraints.")
with gr.Row():
# Left Column: User Controls
with gr.Column(scale=1):
gr.Markdown("### Search Filters")
# Defaulting to 60k to match typical entry-level EV searches
budget_slider = gr.Slider(minimum=50000, maximum=160000, step=5000, value=90000, label="Maximum Budget (₹)")
range_slider = gr.Slider(minimum=50, maximum=150, step=5, value=75, label="Minimum Range Required (km)")
search_btn = gr.Button("Find My EV", variant="primary")
# Right Column: Data Output
with gr.Column(scale=2):
gr.Markdown("### Recommended Models")
# Gradio automatically renders Pandas Dataframes as beautiful, interactive tables
output_table = gr.Dataframe(headers=["Model", "Price (INR)", "Real Range (km)", "Top Speed (kmph)", "Charging Time (Hrs)"])
# Wire the button to the logic function
search_btn.click(fn=recommend_ev, inputs=[budget_slider, range_slider], outputs=output_table)
# Launch the app
app.launch()