Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,56 +1,33 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
import
|
| 5 |
-
import plotly.express as px
|
| 6 |
-
import matplotlib.pyplot as plt
|
| 7 |
-
from config import NREL_API_KEY, IEA_API_KEY, IRENA_API_KEY, DOE_API_KEY, GROQ_API_KEY
|
| 8 |
-
from data_analysis import fetch_hydrogen_data, analyze_hydrogen_data, groq_ai_analysis
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
st.set_page_config(page_title="
|
| 12 |
|
| 13 |
-
# Sidebar
|
| 14 |
-
st.sidebar.header("
|
| 15 |
-
|
| 16 |
-
selected_api = st.sidebar.radio("Select API for Hydrogen Data:", api_options)
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
# If no data, try alternative APIs
|
| 22 |
-
if hydrogen_data.empty:
|
| 23 |
-
st.warning(f"No data found from {selected_api}. Fetching from alternative sources...")
|
| 24 |
-
for api in api_options:
|
| 25 |
-
if api != selected_api:
|
| 26 |
-
hydrogen_data = fetch_hydrogen_data(api)
|
| 27 |
-
if not hydrogen_data.empty:
|
| 28 |
-
st.success(f"Data successfully retrieved from {api}")
|
| 29 |
-
break
|
| 30 |
-
|
| 31 |
-
# Display Data
|
| 32 |
-
st.title("🚀 AI-Powered Hydrogen Electrolysis Dashboard")
|
| 33 |
-
st.subheader(f"Real-Time Data from {selected_api}")
|
| 34 |
-
|
| 35 |
-
if not hydrogen_data.empty:
|
| 36 |
-
st.dataframe(hydrogen_data)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
else:
|
| 56 |
-
st.error("No data available from all sources. Please try again later.")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
from data_fetcher import get_hydrogen_data
|
| 3 |
+
from groq_analysis import analyze_hydrogen_data
|
| 4 |
+
from visuals import plot_hydrogen_capacity
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Set page title and layout
|
| 7 |
+
st.set_page_config(page_title="Hydrogen Analysis AI App", layout="wide")
|
| 8 |
|
| 9 |
+
# Sidebar Input
|
| 10 |
+
st.sidebar.header("🔧 Fetch Real-Time Hydrogen Data")
|
| 11 |
+
fetch_data = st.sidebar.button("Fetch Data from NREL API")
|
|
|
|
| 12 |
|
| 13 |
+
# Title
|
| 14 |
+
st.title("🚀 AI-Powered Hydrogen Electrolysis Analysis")
|
| 15 |
+
st.write("Fetching real-time hydrogen production data and AI-driven insights.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
+
# Fetch Data
|
| 18 |
+
if fetch_data:
|
| 19 |
+
data = get_hydrogen_data()
|
| 20 |
+
|
| 21 |
+
if isinstance(data, dict) and "error" in data:
|
| 22 |
+
st.error(data["error"])
|
| 23 |
+
else:
|
| 24 |
+
st.subheader("📊 Hydrogen Production Data")
|
| 25 |
+
st.write(data)
|
| 26 |
+
|
| 27 |
+
# AI Analysis
|
| 28 |
+
ai_insights = analyze_hydrogen_data(data)
|
| 29 |
+
st.subheader("🧠 AI Insights from Llama 3")
|
| 30 |
+
st.write(ai_insights)
|
| 31 |
+
|
| 32 |
+
# Visualizations
|
| 33 |
+
plot_hydrogen_capacity(data)
|
|
|
|
|
|