Files

copied

Scanning the repository...

Last update 3 weeks 3 days by Niranjani_2005
Files
Book1.xlsx
Cargobike.kicad_pcb
Cargobike.kicad_sch
GyroScooter.mp4
Gyroscooter 3D model.mp4
LICENSE
README.md
TNWISE2025_PPT_FORMAT kgisl ece.pptx
app.py
cargobike_ppt.pptx
app.py
import streamlit as st import matplotlib.pyplot as plt import folium import requests import pandas as pd from streamlit_folium import folium_static from geopy.distance import geodesic # Page Configuration st.set_page_config(page_title="Cargo Bike AI Panel", layout="wide") st.title("🚲 AI-Powered Cargo Bike Panel") # Sidebar: User Input st.sidebar.header("πŸ”§ Customize Your Ride") if 'ride_history' not in st.session_state: st.session_state.ride_history = [] # Battery & Efficiency Inputs battery_capacity = st.sidebar.number_input("πŸ”‹ Battery Capacity (Wh)", min_value=500, max_value=5000, value=2000) wh_per_km = st.sidebar.number_input("⚑ Power Consumption per km (Wh)", min_value=5, max_value=20, value=10) weight_load = st.sidebar.slider("πŸ“¦ Load Weight (kg)", 0, 100, 10) terrain_type = st.sidebar.selectbox("πŸ”οΈ Terrain Type", ["Flat", "Hilly", "Mixed"]) weather_condition = st.sidebar.selectbox("🌦️ Weather Condition", ["Normal", "Windy", "Rainy", "Extreme Heat"]) # Fuel Cost (Fixed for Coimbatore) electric_cost_per_km = 0.12 # β‚Ή0.12 per km petrol_cost_per_km = 3.38 # β‚Ή3.38 per km # Route Input st.subheader("πŸ—ΊοΈ AI Route Optimization & Live Tracking") source = st.text_input("πŸ“ Enter Source Location", "Gandhipuram, Coimbatore") destination = st.text_input("πŸ“ Enter Destination Location", "Peelamedu, Coimbatore") # Function to Get Coordinates def get_coordinates_osm(place): url = f"https://nominatim.openstreetmap.org/search?format=json&q={place}" headers = {"User-Agent": "CargoBikeAI/1.0"} try: response = requests.get(url, headers=headers, timeout=5) data = response.json() if response.status_code == 200 and len(data) > 0: return float(data[0]["lat"]), float(data[0]["lon"]) except requests.exceptions.RequestException as e: st.error(f"❌ Network Error: {e}") return None def get_distance(source_coords, dest_coords): url = f"http://router.project-osrm.org/route/v1/driving/{source_coords[1]},{source_coords[0]};{dest_coords[1]},{dest_coords[0]}?overview=false" try: response = requests.get(url, timeout=5) data = response.json() if "routes" in data and len(data["routes"]) > 0: return data["routes"][0]["distance"] / 1000 # Convert meters to km except requests.exceptions.RequestException: st.warning("⚠️ Unable to fetch road distance. Using geodesic distance.") return geodesic(source_coords, dest_coords).km # Fallback to geodesic # AI-Powered Battery Life Prediction def predict_battery_usage(distance, terrain, weight, weather): factor = 1.0 if terrain == "Hilly": factor += 0.3 elif terrain == "Mixed": factor += 0.15 if weight > 50: factor += 0.2 elif weight > 25: factor += 0.1 if weather == "Windy": factor += 0.1 elif weather == "Rainy": factor += 0.2 elif weather == "Extreme Heat": factor += 0.3 return wh_per_km * distance * factor # Function to Get Real-Time Traffic Route def get_dynamic_route(start_coords, end_coords): url = f"http://router.project-osrm.org/route/v1/driving/{start_coords[1]},{start_coords[0]};{end_coords[1]},{end_coords[0]}?overview=full&geometries=geojson" try: response = requests.get(url, timeout=5) data = response.json() if response.status_code == 200 and "routes" in data and len(data["routes"]) > 0: return data["routes"][0]["geometry"]["coordinates"] except requests.exceptions.RequestException: st.warning("⚠️ Live traffic rerouting unavailable.") return None # Button to Find Route if st.button("Find Optimized Route"): source_coords = get_coordinates_osm(source) destination_coords = get_coordinates_osm(destination) if source_coords and destination_coords: distance_traveled = get_distance(source_coords, destination_coords) battery_used = predict_battery_usage(distance_traveled, terrain_type, weight_load, weather_condition) battery_remaining = max(0, battery_capacity - battery_used) electric_cost = electric_cost_per_km * distance_traveled petrol_cost = petrol_cost_per_km * distance_traveled co2_saved = (120 - 20) * distance_traveled # COβ‚‚ saved st.session_state.ride_history.append([ source, destination, distance_traveled, battery_used, battery_remaining, electric_cost, petrol_cost ]) # **Battery Usage Alert** if len(st.session_state.ride_history) > 3: st.warning("⚠️ Multiple rides detected! Battery usage is high, ride carefully!") # **Map Visualization** m = folium.Map(location=source_coords, zoom_start=13) folium.Marker(source_coords, tooltip="Start", icon=folium.Icon(color="green")).add_to(m) folium.Marker(destination_coords, tooltip="Destination", icon=folium.Icon(color="red")).add_to(m) route = get_dynamic_route(source_coords, destination_coords) if route: folium.PolyLine([(lat, lon) for lon, lat in route], color="blue", weight=3).add_to(m) folium_static(m) # **Cost Analysis** st.subheader("πŸ’° Cost & Battery Savings") col1, col2 = st.columns(2) with col1: st.metric(label="Electric Bike Cost", value=f"β‚Ή{electric_cost:.2f}") with col2: st.metric(label="Petrol Bike Cost", value=f"β‚Ή{petrol_cost:.2f}") # **Ride History Table** if len(st.session_state.ride_history) > 0: st.subheader("πŸ“œ Ride History") df = pd.DataFrame(st.session_state.ride_history, columns=[ "Source", "Destination", "Distance (km)", "Battery Used (Wh)", "Remaining Battery (Wh)", "Electric Cost (β‚Ή)", "Petrol Cost (β‚Ή)" ]) st.dataframe(df, use_container_width=True) # --------- GRAPHS SECTION --------- with st.expander("πŸ“Š Graphs - Cost, Efficiency & COβ‚‚ Comparison"): distances = [ride[2] for ride in st.session_state.ride_history] electric_costs = [ride[5] for ride in st.session_state.ride_history] petrol_costs = [ride[6] for ride in st.session_state.ride_history] st.subheader("πŸ“‰ Cost Comparison Over Distance") fig, ax = plt.subplots(figsize=(4,3)) ax.plot(distances, electric_costs, marker="o", linestyle="-", label="Electric Cost (β‚Ή)", color="green") ax.plot(distances, petrol_costs, marker="o", linestyle="-", label="Petrol Cost (β‚Ή)", color="red") ax.set_xlabel("Distance (km)") ax.set_ylabel("Cost (β‚Ή)") ax.legend() st.pyplot(fig) st.subheader("⚑ Efficiency Comparison Over Distance") battery_usage = [ride[3] for ride in st.session_state.ride_history] fig, ax = plt.subplots(figsize=(4,3)) ax.plot(distances, battery_usage, marker="o", linestyle="-", label="Battery Used (Wh)", color="purple") ax.set_xlabel("Distance (km)") ax.set_ylabel("Battery Consumption (Wh)") ax.legend() st.pyplot(fig) st.subheader("🌱 COβ‚‚ Savings Over Distance") co2_savings = [(120 - 20) * ride[2] for ride in st.session_state.ride_history] fig, ax = plt.subplots(figsize=(4,3)) ax.plot(distances, co2_savings, marker="o", linestyle="-", label="COβ‚‚ Saved (g)", color="blue") ax.set_xlabel("Distance (km)") ax.set_ylabel("COβ‚‚ Saved (g)") ax.legend() st.pyplot(fig)
Report a bug