mjolnir1122 commited on
Commit
ef77706
·
verified ·
1 Parent(s): cc44315

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ import pandas as pd
4
+ import json
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
+ # Streamlit UI
11
+ st.set_page_config(page_title="AI Hydrogen Electrolysis Dashboard", layout="wide")
12
+
13
+ # Sidebar - API selection
14
+ st.sidebar.header("🔍 Data Sources")
15
+ api_options = ["NREL", "IEA", "IRENA", "DOE"]
16
+ selected_api = st.sidebar.radio("Select API for Hydrogen Data:", api_options)
17
+
18
+ # Fetch Data
19
+ hydrogen_data = fetch_hydrogen_data(selected_api)
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
+ # Plot Electrolysis Efficiency vs. Cost
39
+ st.subheader("📊 Hydrogen Production Trends")
40
+ fig = px.scatter(hydrogen_data, x="Efficiency (%)", y="Cost ($/kg)", color="Technology",
41
+ title="Hydrogen Production Efficiency vs. Cost")
42
+ st.plotly_chart(fig)
43
+
44
+ # Bar Chart - Hydrogen Production Rates by Source
45
+ st.subheader("⚡ Hydrogen Production Rate by Technology")
46
+ fig2 = px.bar(hydrogen_data, x="Technology", y="Hydrogen Production Rate (kg/h)",
47
+ title="Hydrogen Production Rate by Technology")
48
+ st.plotly_chart(fig2)
49
+
50
+ # AI Prediction & Analysis using Groq API
51
+ st.subheader("🤖 AI-Powered Electrolysis Analysis")
52
+ ai_prediction = groq_ai_analysis(hydrogen_data)
53
+ st.write(ai_prediction)
54
+
55
+ else:
56
+ st.error("No data available from all sources. Please try again later.")