AndySAnker commited on
Commit
a9d689d
1 Parent(s): 7e8364a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -23,7 +23,7 @@ def get_POMFinder():
23
  return y, y_onehotenc_cat, y_onehotenc_values, POMFinder
24
 
25
 
26
- def PDF_Preparation(Your_PDF_Name, Qmin, Qmax, Qdamp, rmax, nyquist, plot=True):
27
  for i in range(1000):
28
  with open(Your_PDF_Name, "r") as file:
29
  data = file.read().splitlines(True)
@@ -58,30 +58,31 @@ def PDF_Preparation(Your_PDF_Name, Qmin, Qmax, Qdamp, rmax, nyquist, plot=True):
58
  # Add experimental parameters to the Gr
59
  Gr = np.expand_dims(np.concatenate((np.expand_dims(Qmin, axis=0), np.expand_dims(Qmax, axis=0), np.expand_dims(Qdamp, axis=0), Gr), axis=0), axis=0)
60
 
61
- if plot:
62
- # Plot the transformation to make sure everything is alright
63
- plt.plot(PDF[:,0], PDF[:,1], label="Original Data")
64
- plt.plot(r, Gr[0,3:], label="Gr ready for ML")
65
- plt.legend()
66
- plt.title("Original Data vs. normalised Data")
67
- plt.xlabel("r (AA)")
68
- plt.ylabel("Gr")
69
- plt.show()
70
 
 
 
 
 
 
 
 
 
 
 
71
  return r, Gr
72
 
73
  def POMPredicter(POMFinder, Gr, y_onehotenc_cat):
74
  y_pred_proba = POMFinder.predict_proba(Gr);
75
  y_pred_proba = y_pred_proba[:,1];
76
- #print (np.shape(y_pred_proba))
77
- #y_pred_proba = y_pred_proba[0];
78
  res = sorted(range(len(y_pred_proba)), key = lambda sub: y_pred_proba[sub]);
79
  res.reverse();
80
- print ("The 1st guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[0]])[2:-2]+"cale.xyz")
81
- print ("The 2nd guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[1]])[2:-2]+"cale.xyz")
82
- print ("The 3rd guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[2]])[2:-2]+"cale.xyz")
83
- print ("The 4th guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[3]])[2:-2]+"cale.xyz")
84
- print ("The 5th guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[4]])[2:-2]+"cale.xyz")
85
 
86
  return res, y_pred_proba
87
 
@@ -120,8 +121,11 @@ else:
120
 
121
  #Predict with POMFinder
122
  y, y_onehotenc_cat, y_onehotenc_values, POMFinder = get_POMFinder()
 
123
  r, Gr = PDF_Preparation(args.data, args.Qmin, args.Qmax, args.Qdamp, rmax=10, nyquist=args.nyquist)
 
124
  res, y_pred_proba = POMPredicter(POMFinder, Gr, y_onehotenc_cat);
 
125
 
126
 
127
  st.subheader('Cite')
 
23
  return y, y_onehotenc_cat, y_onehotenc_values, POMFinder
24
 
25
 
26
+ def PDF_Preparation(Your_PDF_Name, Qmin, Qmax, Qdamp, rmax, nyquist):
27
  for i in range(1000):
28
  with open(Your_PDF_Name, "r") as file:
29
  data = file.read().splitlines(True)
 
58
  # Add experimental parameters to the Gr
59
  Gr = np.expand_dims(np.concatenate((np.expand_dims(Qmin, axis=0), np.expand_dims(Qmax, axis=0), np.expand_dims(Qdamp, axis=0), Gr), axis=0), axis=0)
60
 
61
+ # Create a new figure object
62
+ fig, ax = plt.subplots()
 
 
 
 
 
 
 
63
 
64
+ # Plot the transformation to make sure everything is alright
65
+ ax.plot(PDF[:,0], PDF[:,1], label="Original Data")
66
+ ax.plot(r, Gr[0,3:], label="Gr ready for ML")
67
+ ax.legend()
68
+ ax.set_title("Original Data vs. normalised Data")
69
+ ax.set_xlabel("r (AA)")
70
+ ax.set_ylabel("Gr")
71
+
72
+ st.pyplot(fig)
73
+
74
  return r, Gr
75
 
76
  def POMPredicter(POMFinder, Gr, y_onehotenc_cat):
77
  y_pred_proba = POMFinder.predict_proba(Gr);
78
  y_pred_proba = y_pred_proba[:,1];
 
 
79
  res = sorted(range(len(y_pred_proba)), key = lambda sub: y_pred_proba[sub]);
80
  res.reverse();
81
+ st.write("The 1st guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[0]])[2:-2]+"cale.xyz")
82
+ st.write("The 2nd guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[1]])[2:-2]+"cale.xyz")
83
+ st.write("The 3rd guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[2]])[2:-2]+"cale.xyz")
84
+ st.write("The 4th guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[3]])[2:-2]+"cale.xyz")
85
+ st.write("The 5th guess from the model is: ", str(y_onehotenc_cat.categories_[0][res[4]])[2:-2]+"cale.xyz")
86
 
87
  return res, y_pred_proba
88
 
 
121
 
122
  #Predict with POMFinder
123
  y, y_onehotenc_cat, y_onehotenc_values, POMFinder = get_POMFinder()
124
+ st.write("POMfinder loaded")
125
  r, Gr = PDF_Preparation(args.data, args.Qmin, args.Qmax, args.Qdamp, rmax=10, nyquist=args.nyquist)
126
+ st.write("Data loaded")
127
  res, y_pred_proba = POMPredicter(POMFinder, Gr, y_onehotenc_cat);
128
+ st.write("Predictions is: ", res)
129
 
130
 
131
  st.subheader('Cite')