Spaces:
Sleeping
Sleeping
| from typing import Any, List | |
| def create_model() -> Any: | |
| try: | |
| import sciann as sn | |
| import numpy as np | |
| x = sn.Variable('x') | |
| y = sn.Variable('y') | |
| net = sn.Functional('u')(x, y) | |
| class SciannWrapper: | |
| def __init__(self, func): | |
| self.func = func | |
| def predict(self, inputs: List[List[float]]): | |
| arr = np.array(inputs) | |
| x_in = arr[:, 0] | |
| y_in = arr[:, 1] if arr.shape[1] > 1 else np.zeros_like(x_in) | |
| out = self.func.predict(x_in, y_in) | |
| return out | |
| def load_weights(self, path: str): | |
| try: | |
| self.func.load_weights(path) | |
| except Exception: | |
| pass | |
| return SciannWrapper(net) | |
| except Exception: | |
| class FallbackModel: | |
| def predict(self, inputs): | |
| out = [] | |
| for row in inputs: | |
| p1 = float(row[0]) if len(row) > 0 else 0.0 | |
| p2 = float(row[1]) if len(row) > 1 else 0.0 | |
| confidence = max(0.0, min(1.0, 0.5 + 0.01 * p1 - 0.001 * p2)) | |
| stress = p1 * 1.5 | |
| strain = p2 * 0.2 | |
| out.append([confidence, stress, strain]) | |
| return out | |
| return FallbackModel() | |