speedometer / app.py
King-Afridi's picture
Update app.py
258680f verified
import streamlit as st
import matplotlib.pyplot as plt
from datetime import datetime
# Function to create a digital speedometer with date and time
def create_digital_speedometer(speed):
# Create a figure and axis for plotting
fig, ax = plt.subplots(figsize=(8, 8))
ax.set_xlim(-1.5, 1.5)
ax.set_ylim(-1.5, 1.5)
ax.set_aspect('equal')
# Background circle (optional for styling)
circle = plt.Circle((0, 0), 1, color='lightgray', lw=10, fill=True)
ax.add_artist(circle)
# Display the current speed in digital format (large)
ax.text(0, 0.2, f"Speed: {speed} km/h", ha='center', va='center', fontsize=40, color='black', fontweight='bold', fontname='monospace')
# Get current date and time
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Display the current date and time (small below the speed)
ax.text(0, -0.3, current_time, ha='center', va='center', fontsize=15, color='black', fontweight='normal', fontname='monospace')
# Title for the plot
ax.set_title("Digital Speedometer", fontsize=18, fontweight='bold')
# Remove axes and ticks
ax.set_xticks([])
ax.set_yticks([])
return fig
# Streamlit Page Configuration
st.set_page_config(page_title="Digital Speedometer", layout="centered")
# Title of the App
st.title("Fully Digital Speedometer")
# Speed input slider
speed = st.slider("Select Speed (km/h)", min_value=0, max_value=200, step=1, value=50)
# Display the digital speedometer with the selected speed
fig = create_digital_speedometer(speed)
st.pyplot(fig)
# Additional description
st.markdown("""
This is a fully digital speedometer that shows the speed in a digital format along with the current date and time.
Adjust the slider to simulate the speed and see the updates in real-time.
""")