Spaces:
Sleeping
Sleeping
Create data_analysis.py
Browse files- data_analysis.py +37 -0
data_analysis.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from config import NREL_API_KEY, IEA_API_KEY, IRENA_API_KEY, DOE_API_KEY, GROQ_API_KEY
|
| 4 |
+
from groq import Groq
|
| 5 |
+
|
| 6 |
+
# Function to fetch hydrogen data from different APIs
|
| 7 |
+
def fetch_hydrogen_data(source):
|
| 8 |
+
if source == "NREL":
|
| 9 |
+
url = f"https://developer.nrel.gov/api/hydrogen/v1/stations.json?api_key={NREL_API_KEY}"
|
| 10 |
+
elif source == "IEA":
|
| 11 |
+
url = f"https://api.iea.org/hydrogen?api_key={IEA_API_KEY}"
|
| 12 |
+
elif source == "IRENA":
|
| 13 |
+
url = f"https://api.irena.org/hydrogen?api_key={IRENA_API_KEY}"
|
| 14 |
+
elif source == "DOE":
|
| 15 |
+
url = f"https://api.doe.gov/hydrogen?api_key={DOE_API_KEY}"
|
| 16 |
+
else:
|
| 17 |
+
return pd.DataFrame()
|
| 18 |
+
|
| 19 |
+
response = requests.get(url)
|
| 20 |
+
if response.status_code == 200:
|
| 21 |
+
data = response.json()
|
| 22 |
+
return pd.DataFrame(data["results"])
|
| 23 |
+
else:
|
| 24 |
+
return pd.DataFrame()
|
| 25 |
+
|
| 26 |
+
# Function for AI-powered analysis using Groq API
|
| 27 |
+
def groq_ai_analysis(data):
|
| 28 |
+
groq_api = Groq(api_key=GROQ_API_KEY)
|
| 29 |
+
|
| 30 |
+
query = f"Analyze hydrogen electrolysis data: {data.to_dict()}"
|
| 31 |
+
|
| 32 |
+
response = groq_api.chat.completions.create(
|
| 33 |
+
messages=[{"role": "user", "content": query}],
|
| 34 |
+
model="llama3-70b-8192"
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
return response.choices[0].message["content"]
|