Inni-23 commited on
Commit
682bc73
·
1 Parent(s): 67b94da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -17
app.py CHANGED
@@ -2,30 +2,31 @@ import gradio as gr
2
  import numpy as np
3
  from tensorflow import keras
4
 
5
- # Load the pre-trained model
6
- model = keras.models.load_model('omni_rnn_0.h5')
 
7
 
8
- def predict(year, proton_density, temperature):
 
 
 
9
  try:
10
  # Ensure the input data has the correct types and ranges
11
- year = int(year)
12
- proton_density = float(proton_density)
13
- temperature = float(temperature)
14
 
15
  # Ensure the input data is within valid ranges
16
- if year < 0 or proton_density < 0 or temperature < 0:
17
- return {"error": "Input values should be non-negative"}
18
 
19
  # Convert input data to a NumPy array
20
- input_data = np.array([year, proton_density, temperature]).reshape(1, -1)
21
 
22
- # Make predictions using the loaded model
23
- predictions = model.predict(input_data)
24
 
25
  # Format the predictions as a dictionary
26
  result = {
27
- "predicted_speed": float(predictions[0, 0]),
28
- "predicted_field_magnitude": float(predictions[0, 1])
29
  }
30
 
31
  return result
@@ -33,11 +34,21 @@ def predict(year, proton_density, temperature):
33
  except Exception as e:
34
  return {"error": str(e)}
35
 
36
- iface = gr.Interface(
37
- fn=predict,
 
38
  inputs=["text", "text", "text"], # Year, Proton Density, Temperature
39
  outputs="json",
40
- title="ReconXploration"
 
 
 
 
 
 
 
41
  )
42
 
43
- iface.launch()
 
 
 
2
  import numpy as np
3
  from tensorflow import keras
4
 
5
+ # Load the pre-trained models
6
+ speed_model = keras.models.load_model('omni_rnn_0.h5')
7
+ power_model = keras.models.load_model('power_model.h5') # Load the second model for power prediction
8
 
9
+ def predict_speed(year, proton_density, temperature):
10
+ # Your existing speed prediction code here
11
+
12
+ def predict_power(speed):
13
  try:
14
  # Ensure the input data has the correct types and ranges
15
+ speed = float(speed)
 
 
16
 
17
  # Ensure the input data is within valid ranges
18
+ if speed < 0:
19
+ return {"error": "Speed should be non-negative"}
20
 
21
  # Convert input data to a NumPy array
22
+ input_data = np.array([speed]).reshape(1, -1)
23
 
24
+ # Make predictions using the loaded power model
25
+ power_prediction = power_model.predict(input_data)
26
 
27
  # Format the predictions as a dictionary
28
  result = {
29
+ "predicted_power": float(power_prediction[0])
 
30
  }
31
 
32
  return result
 
34
  except Exception as e:
35
  return {"error": str(e)}
36
 
37
+ # Create the Gradio interfaces
38
+ speed_interface = gr.Interface(
39
+ fn=predict_speed,
40
  inputs=["text", "text", "text"], # Year, Proton Density, Temperature
41
  outputs="json",
42
+ title="Solar Wind Speed Prediction"
43
+ )
44
+
45
+ power_interface = gr.Interface(
46
+ fn=predict_power,
47
+ inputs="text", # Speed prediction from the previous step
48
+ outputs="json",
49
+ title="Solar Wind Power Generation Prediction"
50
  )
51
 
52
+ # Launch the interfaces
53
+ speed_interface.launch()
54
+ power_interface.launch()