Spaces:
Sleeping
Sleeping
Commit
·
5dc2797
1
Parent(s):
14409e7
test_interface
Browse files
app.py
CHANGED
|
@@ -1,101 +1,128 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import json
|
| 3 |
import pandas as pd
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
st.
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
# Initialize session state variables
|
| 30 |
-
if 'api_token' not in st.session_state:
|
| 31 |
-
st.session_state.api_token = DEFAULT_TOKEN
|
| 32 |
-
if 'current_file' not in st.session_state:
|
| 33 |
-
st.session_state.current_file = None
|
| 34 |
-
if 'json_data' not in st.session_state:
|
| 35 |
-
st.session_state.json_data = None
|
| 36 |
-
if 'api_response' not in st.session_state:
|
| 37 |
-
st.session_state.api_response = None
|
| 38 |
-
|
| 39 |
-
# Sidebar configuration
|
| 40 |
-
with st.sidebar:
|
| 41 |
-
st.markdown("## API Configuration")
|
| 42 |
-
api_token = st.text_input("API Token", value=st.session_state.api_token, type="password")
|
| 43 |
-
if api_token:
|
| 44 |
-
st.session_state.api_token = api_token
|
| 45 |
-
|
| 46 |
-
st.markdown("""
|
| 47 |
-
## About
|
| 48 |
-
This dashboard provides analysis of energy data through various services
|
| 49 |
-
including NILM analysis, consumption and production forecasting.
|
| 50 |
-
""")
|
| 51 |
-
|
| 52 |
-
# Main page content
|
| 53 |
-
st.title("Energy Data Analysis Dashboard")
|
| 54 |
-
|
| 55 |
-
# Welcome message and service descriptions
|
| 56 |
-
st.markdown("""
|
| 57 |
-
Welcome to the Energy Data Analysis Dashboard! This platform provides comprehensive tools for analyzing energy consumption and production data.
|
| 58 |
-
|
| 59 |
-
### Available Services
|
| 60 |
-
|
| 61 |
-
You can access the following services through the navigation menu on the left:
|
| 62 |
-
|
| 63 |
-
#### 1. Energy Consumption Forecasting
|
| 64 |
-
- **Short Term**: Predict energy consumption patterns in the near future
|
| 65 |
-
- **Long Term**: Generate long-range consumption forecasts
|
| 66 |
-
|
| 67 |
-
#### 2. Energy Production Analysis
|
| 68 |
-
- **Short Term Production**: Forecast PV panel energy production
|
| 69 |
-
- **NILM Analysis**: Non-intrusive load monitoring for detailed consumption breakdown
|
| 70 |
-
|
| 71 |
-
#### 3. Advanced Analytics
|
| 72 |
-
- **Anomaly Detection**: Identify unusual patterns in energy consumption
|
| 73 |
-
|
| 74 |
-
### Getting Started
|
| 75 |
-
|
| 76 |
-
1. Select a service from the navigation menu on the left
|
| 77 |
-
2. Upload your energy data file in JSON format
|
| 78 |
-
3. Configure your API token if needed
|
| 79 |
-
4. Run the analysis and explore the results
|
| 80 |
-
|
| 81 |
-
Each service page provides specific visualizations and analytics tailored to your needs.
|
| 82 |
-
""")
|
| 83 |
-
|
| 84 |
-
# Add version info and additional resources in an expander
|
| 85 |
-
with st.expander("Additional Information"):
|
| 86 |
-
st.markdown("""
|
| 87 |
-
### Usage Tips
|
| 88 |
-
- Ensure your data is in the correct JSON format
|
| 89 |
-
- Keep your API token secure
|
| 90 |
-
- Use the visualization tools to explore your data
|
| 91 |
-
- Export results for further analysis
|
| 92 |
-
|
| 93 |
-
### Support
|
| 94 |
-
For technical support or questions about the services, please contact your system administrator.
|
| 95 |
-
""")
|
| 96 |
-
|
| 97 |
-
# Footer
|
| 98 |
-
st.markdown("""
|
| 99 |
-
---
|
| 100 |
-
Made with ❤️ by tLINKS Foundation
|
| 101 |
-
""")
|
|
|
|
| 1 |
+
# import streamlit as st
|
| 2 |
+
# import json
|
| 3 |
+
# import pandas as pd
|
| 4 |
+
# import plotly.express as px
|
| 5 |
+
# import requests
|
| 6 |
+
# from datetime import datetime
|
| 7 |
+
# import plotly.graph_objects as go
|
| 8 |
+
# import os
|
| 9 |
+
# import logging
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# # Configure the main page
|
| 15 |
+
# st.set_page_config(
|
| 16 |
+
# page_title="Energy Data Analysis Dashboard",
|
| 17 |
+
# page_icon="⚡",
|
| 18 |
+
# layout="wide",
|
| 19 |
+
# initial_sidebar_state="expanded"
|
| 20 |
+
# )
|
| 21 |
+
|
| 22 |
+
# #DEFAULT_TOKEN = os.getenv('NILM_API_TOKEN', '')
|
| 23 |
+
# DEFAULT_TOKEN = 'p2s8X9qL4zF7vN3mK6tR1bY5cA0wE3hJ'
|
| 24 |
+
# print(DEFAULT_TOKEN)
|
| 25 |
+
# logger = logging.getLogger("Data cellar demo")
|
| 26 |
+
|
| 27 |
+
# logger.info(f"token : {DEFAULT_TOKEN}")
|
| 28 |
+
|
| 29 |
+
# # Initialize session state variables
|
| 30 |
+
# if 'api_token' not in st.session_state:
|
| 31 |
+
# st.session_state.api_token = DEFAULT_TOKEN
|
| 32 |
+
# if 'current_file' not in st.session_state:
|
| 33 |
+
# st.session_state.current_file = None
|
| 34 |
+
# if 'json_data' not in st.session_state:
|
| 35 |
+
# st.session_state.json_data = None
|
| 36 |
+
# if 'api_response' not in st.session_state:
|
| 37 |
+
# st.session_state.api_response = None
|
| 38 |
+
|
| 39 |
+
# # Sidebar configuration
|
| 40 |
+
# with st.sidebar:
|
| 41 |
+
# st.markdown("## API Configuration")
|
| 42 |
+
# api_token = st.text_input("API Token", value=st.session_state.api_token, type="password")
|
| 43 |
+
# if api_token:
|
| 44 |
+
# st.session_state.api_token = api_token
|
| 45 |
+
|
| 46 |
+
# st.markdown("""
|
| 47 |
+
# ## About
|
| 48 |
+
# This dashboard provides analysis of energy data through various services
|
| 49 |
+
# including NILM analysis, consumption and production forecasting.
|
| 50 |
+
# """)
|
| 51 |
+
|
| 52 |
+
# # Main page content
|
| 53 |
+
# st.title("Energy Data Analysis Dashboard")
|
| 54 |
+
|
| 55 |
+
# # Welcome message and service descriptions
|
| 56 |
+
# st.markdown("""
|
| 57 |
+
# Welcome to the Energy Data Analysis Dashboard! This platform provides comprehensive tools for analyzing energy consumption and production data.
|
| 58 |
+
|
| 59 |
+
# ### Available Services
|
| 60 |
+
|
| 61 |
+
# You can access the following services through the navigation menu on the left:
|
| 62 |
+
|
| 63 |
+
# #### 1. Energy Consumption Forecasting
|
| 64 |
+
# - **Short Term**: Predict energy consumption patterns in the near future
|
| 65 |
+
# - **Long Term**: Generate long-range consumption forecasts
|
| 66 |
+
|
| 67 |
+
# #### 2. Energy Production Analysis
|
| 68 |
+
# - **Short Term Production**: Forecast PV panel energy production
|
| 69 |
+
# - **NILM Analysis**: Non-intrusive load monitoring for detailed consumption breakdown
|
| 70 |
+
|
| 71 |
+
# #### 3. Advanced Analytics
|
| 72 |
+
# - **Anomaly Detection**: Identify unusual patterns in energy consumption
|
| 73 |
+
|
| 74 |
+
# ### Getting Started
|
| 75 |
+
|
| 76 |
+
# 1. Select a service from the navigation menu on the left
|
| 77 |
+
# 2. Upload your energy data file in JSON format
|
| 78 |
+
# 3. Configure your API token if needed
|
| 79 |
+
# 4. Run the analysis and explore the results
|
| 80 |
+
|
| 81 |
+
# Each service page provides specific visualizations and analytics tailored to your needs.
|
| 82 |
+
# """)
|
| 83 |
+
|
| 84 |
+
# # Add version info and additional resources in an expander
|
| 85 |
+
# with st.expander("Additional Information"):
|
| 86 |
+
# st.markdown("""
|
| 87 |
+
# ### Usage Tips
|
| 88 |
+
# - Ensure your data is in the correct JSON format
|
| 89 |
+
# - Keep your API token secure
|
| 90 |
+
# - Use the visualization tools to explore your data
|
| 91 |
+
# - Export results for further analysis
|
| 92 |
+
|
| 93 |
+
# ### Support
|
| 94 |
+
# For technical support or questions about the services, please contact your system administrator.
|
| 95 |
+
# """)
|
| 96 |
+
|
| 97 |
+
# # Footer
|
| 98 |
+
# st.markdown("""
|
| 99 |
+
# ---
|
| 100 |
+
# Made with ❤️ by tLINKS Foundation
|
| 101 |
+
# """)
|
| 102 |
+
|
| 103 |
import streamlit as st
|
|
|
|
| 104 |
import pandas as pd
|
| 105 |
+
import pickle
|
| 106 |
+
# Load Model
|
| 107 |
+
model = pickle.load(open('logreg_model.pkl', 'rb'))
|
| 108 |
+
st.title('Iris Variety Prediction')
|
| 109 |
+
# Form
|
| 110 |
+
with st.form(key='form_parameters'):
|
| 111 |
+
sepal_length = st.slider('Sepal Length', 4.0, 8.0, 4.0)
|
| 112 |
+
sepal_width = st.slider('Sepal Width', 2.0, 4.5, 2.0)
|
| 113 |
+
petal_length = st.slider('Petal Length', 1.0, 7.0, 1.0)
|
| 114 |
+
petal_width = st.slider('Petal Width', 0.1, 2.5, 0.1)
|
| 115 |
+
st.markdown('---')
|
| 116 |
+
submitted = st.form_submit_button('Predict')
|
| 117 |
+
# Data Inference
|
| 118 |
+
data_inf = {
|
| 119 |
+
'sepal.length': sepal_length,
|
| 120 |
+
'sepal.width': sepal_width,
|
| 121 |
+
'petal.length': petal_length,
|
| 122 |
+
'petal.width': petal_width
|
| 123 |
+
}
|
| 124 |
+
data_inf = pd.DataFrame([data_inf])
|
| 125 |
+
if submitted:
|
| 126 |
+
# Predict using Logistic Regression
|
| 127 |
+
y_pred_inf = model.predict(data_inf)
|
| 128 |
+
st.write('## Iris Variety = '+ str(y_pred_inf))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|