Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- backend/main.py +4 -2
- tests/test_api.py +8 -5
backend/main.py
CHANGED
|
@@ -143,7 +143,7 @@ def force_sync():
|
|
| 143 |
|
| 144 |
@app.post("/explain")
|
| 145 |
async def explain(data: PatientData):
|
| 146 |
-
eng = ml_engine.get_ensemble()
|
| 147 |
if not eng or 'rf' not in eng.models:
|
| 148 |
return {"error": "RF Model unavailable for explanation."}
|
| 149 |
|
|
@@ -172,7 +172,9 @@ async def explain(data: PatientData):
|
|
| 172 |
|
| 173 |
@app.get("/export_tinyml")
|
| 174 |
def export_tinyml(model_name: str = "rf", quantize: bool = False):
|
| 175 |
-
eng = ml_engine.get_ensemble()
|
|
|
|
|
|
|
| 176 |
return generate_c_code(eng, model_name, quantize)
|
| 177 |
|
| 178 |
def _run_mlops_ingest(csv_bytes: bytes):
|
|
|
|
| 143 |
|
| 144 |
@app.post("/explain")
|
| 145 |
async def explain(data: PatientData):
|
| 146 |
+
eng = ml_engine.get_ensemble() if ml_engine else None
|
| 147 |
if not eng or 'rf' not in eng.models:
|
| 148 |
return {"error": "RF Model unavailable for explanation."}
|
| 149 |
|
|
|
|
| 172 |
|
| 173 |
@app.get("/export_tinyml")
|
| 174 |
def export_tinyml(model_name: str = "rf", quantize: bool = False):
|
| 175 |
+
eng = ml_engine.get_ensemble() if ml_engine else None
|
| 176 |
+
if not eng:
|
| 177 |
+
return {"error": "Models untrained or engine offline"}
|
| 178 |
return generate_c_code(eng, model_name, quantize)
|
| 179 |
|
| 180 |
def _run_mlops_ingest(csv_bytes: bytes):
|
tests/test_api.py
CHANGED
|
@@ -6,24 +6,27 @@ import os
|
|
| 6 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../backend')))
|
| 7 |
from main import app
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
def test_history_endpoint():
|
| 12 |
response = client.get("/history")
|
| 13 |
assert response.status_code == 200
|
| 14 |
assert isinstance(response.json(), list)
|
| 15 |
|
| 16 |
-
def test_dataset_endpoint():
|
| 17 |
response = client.get("/dataset")
|
| 18 |
assert response.status_code == 200
|
| 19 |
assert isinstance(response.json(), list)
|
| 20 |
|
| 21 |
-
def test_export_tinyml_random_forest():
|
| 22 |
response = client.get("/export_tinyml?model_name=rf")
|
| 23 |
|
| 24 |
if response.status_code == 200:
|
| 25 |
data = response.json()
|
| 26 |
if "error" in data:
|
| 27 |
-
assert "not found" in data["error"].lower()
|
| 28 |
else:
|
| 29 |
assert "code" in data or "c_code" in data
|
|
|
|
| 6 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../backend')))
|
| 7 |
from main import app
|
| 8 |
|
| 9 |
+
@pytest.fixture
|
| 10 |
+
def client():
|
| 11 |
+
with TestClient(app) as c:
|
| 12 |
+
yield c
|
| 13 |
|
| 14 |
+
def test_history_endpoint(client):
|
| 15 |
response = client.get("/history")
|
| 16 |
assert response.status_code == 200
|
| 17 |
assert isinstance(response.json(), list)
|
| 18 |
|
| 19 |
+
def test_dataset_endpoint(client):
|
| 20 |
response = client.get("/dataset")
|
| 21 |
assert response.status_code == 200
|
| 22 |
assert isinstance(response.json(), list)
|
| 23 |
|
| 24 |
+
def test_export_tinyml_random_forest(client):
|
| 25 |
response = client.get("/export_tinyml?model_name=rf")
|
| 26 |
|
| 27 |
if response.status_code == 200:
|
| 28 |
data = response.json()
|
| 29 |
if "error" in data:
|
| 30 |
+
assert "not found" in data["error"].lower() or "models untrained" in data["error"].lower()
|
| 31 |
else:
|
| 32 |
assert "code" in data or "c_code" in data
|