mjolnir1122 commited on
Commit
0ac596b
·
verified ·
1 Parent(s): d045339

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -32
app.py CHANGED
@@ -1,43 +1,36 @@
1
- import sys
2
  import os
3
  import streamlit as st
4
- from data_fetcher import get_hydrogen_data
5
- from groq_analysis import analyze_hydrogen_data
6
- from visuals import plot_hydrogen_capacity
 
7
 
8
- # Ensure the script can find other modules
9
- sys.path.append(os.path.dirname(os.path.abspath(__file__)))
10
-
11
- # Import project modules
12
  from data_fetcher import get_hydrogen_data
13
- from groq_analysis import analyze_hydrogen_data
14
  from visuals import plot_hydrogen_capacity
15
 
16
- # Set page title and layout
17
- st.set_page_config(page_title="Hydrogen Analysis AI App", layout="wide")
18
-
19
- # Sidebar Input
20
- st.sidebar.header("🔧 Fetch Real-Time Hydrogen Data")
21
- fetch_data = st.sidebar.button("Fetch Data from NREL API")
22
 
23
- # Title
24
- st.title("🚀 AI-Powered Hydrogen Electrolysis Analysis")
25
- st.write("Fetching real-time hydrogen production data and AI-driven insights.")
 
26
 
27
- # Fetch Data
28
- if fetch_data:
29
- data = get_hydrogen_data()
30
 
31
- if isinstance(data, dict) and "error" in data:
32
- st.error(data["error"])
33
- else:
34
- st.subheader("📊 Hydrogen Production Data")
35
- st.write(data)
36
 
37
- # AI Analysis
38
- ai_insights = analyze_hydrogen_data(data)
39
- st.subheader("🧠 AI Insights from Llama 3")
40
- st.write(ai_insights)
41
 
42
- # Visualizations
43
- plot_hydrogen_capacity(data)
 
 
 
 
 
1
  import os
2
  import streamlit as st
3
+ import pandas as pd
4
+ import faiss
5
+ import numpy as np
6
+ from groq import Groq
7
 
8
+ # Import custom modules
 
 
 
9
  from data_fetcher import get_hydrogen_data
 
10
  from visuals import plot_hydrogen_capacity
11
 
12
+ # Load environment variables (API Keys)
13
+ NREL_API_KEY = os.getenv("NREL_API_KEY")
14
+ GROQ_API_KEY = os.getenv("GROQ_API_KEY")
 
 
 
15
 
16
+ # ✅ Ensure API keys are set
17
+ if not NREL_API_KEY:
18
+ st.error(" ERROR: NREL API Key is missing! Please set it in environment variables.")
19
+ st.stop()
20
 
21
+ if not GROQ_API_KEY:
22
+ st.error("❌ ERROR: Groq API Key is missing! Please set it in environment variables.")
23
+ st.stop()
24
 
25
+ # Fetch real-time hydrogen data
26
+ hydrogen_data = get_hydrogen_data()
 
 
 
27
 
28
+ # Display UI
29
+ st.set_page_config(page_title="HydroGen-AI", layout="wide")
30
+ st.title("🔬 HydroGen-AI: Green Hydrogen Techno-Economic Analyzer")
 
31
 
32
+ if hydrogen_data is not None:
33
+ st.sidebar.subheader("📡 Real-time Hydrogen Data (NREL API)")
34
+ st.sidebar.write(hydrogen_data.head(5))
35
+ else:
36
+ st.sidebar.warning("⚠️ No hydrogen data available from NREL API.")