Spaces:
Sleeping
Sleeping
| #this is the original app.py file, and has been left out for Hugging Face. It works well for Streamlit locallly | |
| import streamlit as st | |
| import os | |
| from src.processing import train_mode_cloud, predict_health_cloud | |
| #st.set_page_config(page_title="Piranaware Cloud", page_icon="☁️", layout="wide") | |
| #st.markdown("""<style>.stApp {background-color: #F0F2F6;}</style>""", unsafe_allow_html=True) | |
| # --- PIRANAWARE COASTAL THEME (CSS) --- | |
| st.markdown(""" | |
| <style> | |
| /* 1. Main Background - Pure black for maximum contrast */ | |
| .stApp { | |
| background-color: #000000; | |
| } | |
| /* 2. Text Color Fix - High visibility yellow */ | |
| .stApp, .stMarkdown, p, label { | |
| color: #FFD700 !important; /* Bright safety yellow */ | |
| } | |
| /* 3. Headers - Strong yellow, slightly warmer */ | |
| h1, h2, h3, h4, h5, h6 { | |
| color: #FFEB3B !important; /* Vivid header yellow */ | |
| font-family: 'Helvetica Neue', sans-serif; | |
| font-weight: 700; | |
| } | |
| /* 4. Tab Styling */ | |
| button[data-baseweb="tab"] { | |
| color: #BDB76B !important; /* Muted yellow for inactive */ | |
| font-weight: 600; | |
| } | |
| button[data-baseweb="tab"][aria-selected="true"] { | |
| color: #FFD700 !important; | |
| border-bottom: 4px solid #FFD700 !important; | |
| background-color: #111111 !important; | |
| } | |
| /* 5. Buttons - Black & yellow safety style */ | |
| div.stButton > button { | |
| background-color: #000000; | |
| color: #FFD700; | |
| border: 3px solid #FFD700; | |
| border-radius: 8px; | |
| font-weight: bold; | |
| } | |
| div.stButton > button:hover { | |
| background-color: #FFD700; | |
| color: #000000; | |
| box-shadow: 0 4px 14px rgba(255, 215, 0, 0.6); | |
| border: 3px solid #FFD700; | |
| } | |
| /* 6. Input Labels */ | |
| .stAudioInput label, .stFileUploader label, .stSelectbox label, .stTextInput label { | |
| color: #FFD700 !important; | |
| font-weight: 700; | |
| } | |
| /* 7. Results Box Styling */ | |
| .result-box-healthy { | |
| background-color: #111111; | |
| border: 2px solid #00FF9C; | |
| border-left: 6px solid #00C781; | |
| padding: 15px; border-radius: 5px; | |
| color: #00FF9C; | |
| } | |
| .result-box-anomaly { | |
| background-color: #111111; | |
| border: 2px solid #FF5252; | |
| border-left: 6px solid #D32F2F; | |
| padding: 15px; border-radius: 5px; | |
| color: #FF5252; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| TEMP_AUDIO_DIR = "temp_audio_uploads" | |
| os.makedirs(TEMP_AUDIO_DIR, exist_ok=True) | |
| def save_audio(audio_value): | |
| if audio_value is None: return None | |
| audio_value.seek(0) | |
| save_path = os.path.join(TEMP_AUDIO_DIR, "input.wav") | |
| with open(save_path, "wb") as f: | |
| f.write(audio_value.read()) | |
| return save_path | |
| # --- LOGIN --- | |
| with st.sidebar: | |
| #st.image("https://img.icons8.com/color/96/speedboat.png", width=80) | |
| st.title("User Login") | |
| st.markdown("### Ensure to use your exact boat ID") | |
| # BOAT ID INPUT | |
| boat_id = st.text_input("Enter Boat ID", value="DEMO_BOAT_01").upper().replace(" ", "_") | |
| st.caption("Training saved online on Google Cloud.") | |
| st.divider() | |
| st.info(f"Active Session:\n**{boat_id}**") | |
| # --- MAIN APP --- | |
| st.title("Piranaware Boat Engine AI") | |
| tab_train, tab_test = st.tabs(["🛠️ Train Baseline", "🩺 Diagnostics"]) | |
| with tab_train: | |
| st.info(f"Training models for: **{boat_id}**. Ensure engine is HEALTHY.") | |
| c1, c2, c3 = st.columns(3) | |
| for col, mode in [(c1, "idle"), (c2, "slow"), (c3, "fast")]: | |
| with col: | |
| st.markdown(f"### {mode.upper()}") | |
| try: audio = st.audio_input(f"Rec {mode}", key=f"rec_{mode}") | |
| except: audio = st.file_uploader(f"Up {mode}", type=['wav'], key=f"rec_{mode}") | |
| if st.button(f"Train {mode.upper()}", key=f"btn_{mode}"): | |
| if audio: | |
| path = save_audio(audio) | |
| with st.spinner("Training & Uploading to Cloud..."): | |
| res = train_mode_cloud(path, mode, boat_id) | |
| st.success(res) | |
| else: | |
| st.error("No Audio") | |
| with tab_test: | |
| st.divider() | |
| st.markdown(f"### Diagnostics for: **{boat_id}**") | |
| col_in, col_out = st.columns([1, 2]) | |
| with col_in: | |
| mode = st.selectbox("Select Mode", ["idle", "slow", "fast"]) | |
| try: test_audio = st.audio_input("Record", key="test") | |
| except: test_audio = st.file_uploader("Upload", type=['wav'], key="test") | |
| btn = st.button("Run Diagnostics") | |
| with col_out: | |
| if btn and test_audio: | |
| path = save_audio(test_audio) | |
| with st.spinner("Downloading Model & Analyzing..."): | |
| report = predict_health_cloud(path, mode, boat_id) | |
| if "HEALTHY" in report: | |
| st.success(report) | |
| elif "ANOMALY" in report: | |
| st.error(report) | |
| else: | |
| st.warning(report) |