import pandas as pd import matplotlib import matplotlib.pyplot as plt import plotly.express as px import numpy as np import plotly.graph_objects as go import sqlite3 from typing import Optional, Dict, Any from datetime import datetime, timedelta import re from pathlib import Path from inference import EagleBlendPredictor import torch # Give torch.classes a benign __path__ so Streamlit won't trigger __getattr__. try: setattr(torch.classes, "__path__", []) except Exception: # Fallback wrapper if direct setattr isn't allowed in your build class _TorchClassesWrapper: def __init__(self, obj): self._obj = obj self.__path__ = [] def __getattr__(self, name): return getattr(self._obj, name) torch.classes = _TorchClassesWrapper(torch.classes) import streamlit as st ##---- fucntions ------ # Load fuel data from CSV (create this file if it doesn't exist) FUEL_CSV_PATH = "fuel_properties.csv" def load_fuel_data(): """Load fuel data from CSV or create default if not exists""" try: df = pd.read_csv(FUEL_CSV_PATH, index_col=0) return df.to_dict('index') except FileNotFoundError: # Create default fuel properties if file doesn't exist default_fuels = { "Gasoline": {f"Property{i+1}": round(0.7 + (i*0.02), 1) for i in range(10)}, "Diesel": {f"Property{i+1}": round(0.8 + (i*0.02), 1) for i in range(10)}, "Ethanol": {f"Property{i+1}": round(0.75 + (i*0.02), 1) for i in range(10)}, "Biodiesel": {f"Property{i+1}": round(0.85 + (i*0.02), 1) for i in range(10)}, "Jet Fuel": {f"Property{i+1}": round(0.78 + (i*0.02), 1) for i in range(10)} } pd.DataFrame(default_fuels).T.to_csv(FUEL_CSV_PATH) return default_fuels # Initialize or load fuel data if 'FUEL_PROPERTIES' not in st.session_state: st.session_state.FUEL_PROPERTIES = load_fuel_data() def save_fuel_data(): """Save current fuel data to CSV""" pd.DataFrame(st.session_state.FUEL_PROPERTIES).T.to_csv(FUEL_CSV_PATH) # FUEL_PROPERTIES = st.session_state.FUEL_PROPERTIES # ---------------------- Page Config ---------------------- st.set_page_config( layout="wide", page_title="Eagle Blend Optimizer", page_icon="๐ฆ ", initial_sidebar_state="expanded" ) # ---------------------- Sidebar Content ---------------------- with st.sidebar: st.markdown("---") st.markdown("### ๐ฆ Developed by eagle-team") st.markdown(""" - Destiny Otto - Williams Alabi - Godswill Otto - Alexander Ifenaike """) st.markdown("---") st.info("Select a tab above to get started.") # ---------------------- Custom Styling ---------------------- ##e0e0e0; st.markdown(""" """, unsafe_allow_html=True) # ---------------------- App Header ---------------------- # --- This is the new header with the subtitle --- st.markdown("""
by eagle-team for the Shell.ai 2025 Hackathon
This tab is your creative sandbox for designing and predicting fuel properties. It has two modes:
Manual Mode (Default):Batch Blend Mode:
1. Define Goals: Enter your desired target values for each of the 10 blend properties. Use the 'Fix Target' toggle for any property that must be met exactly.
2. Select Components: Choose up to 5 base components. You can load them from the registry to auto-fill their data or enter them manually.
3. Configure & Run: Decide if cost should be a factor in the optimization, then click 'Run Optimization'. A spinner will appear while the process runs.
4. Analyze Results: After completion, the best solution is shown by default. You can view other potential solutions from the dropdown. The results include optimal component fractions and the final blend properties.
5. Save & Download: Give your chosen solution a name and save it to the blends database for future use in the Comparison tab.
This tab allows you to perform a side-by-side analysis of up to three saved blends.
1. Select Scenarios: Use the three dropdown menus at the top to select the saved blends you wish to compare.
2. Review Overviews: Key information for each selected blend, including its composition and final properties, will be displayed in summary cards.
3. Analyze Charts: The charts provide a deep dive into how the blends compare on cost, property profiles, quality, and composition.
4. Export: Click the 'Export to PDF' button to generate a downloadable report containing all the charts and data for your selected comparison.
This tab is your central database for managing all blend components and saved blends.
1. Add Components/Blends: You can add a single component manually using the form or upload a CSV file for batch additions of components or blends. Download the templates to ensure your file format is correct.
2. View & Manage Data: Use the dropdown to switch between viewing 'Components' and 'Blends'. The table shows all saved records.
3. Search & Delete: Use the search bar to filter the table. To delete records, check the 'Select' box next to the desired rows and click the 'Delete Selected' button that appears.
KPI Cards: These cards give a quick summary of the model's health. Rยฒ Score is its accuracy grade, while MSE and MAPE measure the average size of its errors.
Rยฒ Score by Blend Property Chart: This chart shows how well the model predicts each specific property. A longer bar means the model is very good at predicting that property.