mystic_CBK commited on
Commit
676cdd2
Β·
1 Parent(s): 5887651

Try to fix fairseq-signals installation with PyTorch 2.0.1 and better debugging

Browse files
ecg_d2c4fdc0-01ee-4210-a027-54a527329cd8.csv ADDED
The diff for this file is too large to render. See raw diff
 
test_real_ecg.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import numpy as np
3
+ import pandas as pd
4
+ import json
5
+
6
+ # Your deployed Hugging Face Space URL
7
+ SPACE_URL = "https://mystic-cbk-ecg-fm-api.hf.space"
8
+
9
+ def load_ecg_data(csv_file):
10
+ """Load ECG data from CSV file"""
11
+ print(f"πŸ“ Loading ECG data from: {csv_file}")
12
+
13
+ # Read the CSV file
14
+ df = pd.read_csv(csv_file)
15
+
16
+ print(f"πŸ“Š ECG Data Shape: {df.shape}")
17
+ print(f"πŸ“Š Leads: {list(df.columns)}")
18
+ print(f"πŸ“Š Samples per lead: {len(df)}")
19
+
20
+ # Convert to the format expected by the API
21
+ # Each lead should be a list of float values
22
+ ecg_data = []
23
+ for lead in df.columns:
24
+ ecg_data.append(df[lead].astype(float).tolist())
25
+
26
+ print(f"βœ… ECG data loaded successfully!")
27
+ print(f"πŸ“Š Data format: {len(ecg_data)} leads Γ— {len(ecg_data[0])} samples")
28
+
29
+ return ecg_data
30
+
31
+ def test_api_with_real_ecg():
32
+ """Test the deployed ECG-FM API with real ECG data"""
33
+
34
+ print("πŸ§ͺ Testing ECG-FM API with Real ECG Data")
35
+ print("=" * 60)
36
+ print(f"🌐 API URL: {SPACE_URL}")
37
+ print()
38
+
39
+ # Load the real ECG data
40
+ try:
41
+ ecg_data = load_ecg_data("ecg_d2c4fdc0-01ee-4210-a027-54a527329cd8.csv")
42
+ except Exception as e:
43
+ print(f"❌ Error loading ECG data: {e}")
44
+ return
45
+
46
+ print()
47
+
48
+ # Test 1: Health check
49
+ print("1️⃣ Testing health endpoint...")
50
+ try:
51
+ r = requests.get(f"{SPACE_URL}/healthz", timeout=30)
52
+ print(f" Status: {r.status_code}")
53
+ if r.status_code == 200:
54
+ response = r.json()
55
+ print(f" Response: {response}")
56
+ print(f" Mode: {response.get('mode', 'unknown')}")
57
+ else:
58
+ print(f" Error: {r.text}")
59
+ except Exception as e:
60
+ print(f" ❌ Error: {e}")
61
+
62
+ print()
63
+
64
+ # Test 2: Root endpoint
65
+ print("2️⃣ Testing root endpoint...")
66
+ try:
67
+ r = requests.get(f"{SPACE_URL}/", timeout=30)
68
+ print(f" Status: {r.status_code}")
69
+ if r.status_code == 200:
70
+ response = r.json()
71
+ print(f" Response: {response}")
72
+ else:
73
+ print(f" Error: {r.text}")
74
+ except Exception as e:
75
+ print(f" ❌ Error: {e}")
76
+
77
+ print()
78
+
79
+ # Test 3: Predict endpoint with REAL ECG data
80
+ print("3️⃣ Testing predict endpoint with REAL ECG data...")
81
+
82
+ # Prepare the payload with real ECG data
83
+ payload = {
84
+ "signal": ecg_data,
85
+ "fs": 500 # 500 Hz sampling rate
86
+ }
87
+
88
+ try:
89
+ print(" πŸ“€ Sending REAL ECG data...")
90
+ print(f" πŸ“Š Input: 12 leads Γ— {len(ecg_data[0])} samples")
91
+ print(f" πŸ“Š Sampling rate: 500 Hz")
92
+ print(f" πŸ“Š Duration: {len(ecg_data[0])/500:.1f} seconds")
93
+ print(" ⏳ Waiting for inference...")
94
+
95
+ r = requests.post(f"{SPACE_URL}/predict", json=payload, timeout=180) # 3 min timeout
96
+ print(f" Status: {r.status_code}")
97
+
98
+ if r.status_code == 200:
99
+ result = r.json()
100
+ print(f" βœ… Success!")
101
+ print(f" πŸ“Š Mode: {result.get('mode', 'unknown')}")
102
+ print(f" πŸ“Š Output shape: {result.get('output_shape', 'unknown')}")
103
+ print(f" πŸ“Š Input shape: {result.get('input_shape', 'unknown')}")
104
+ print(f" πŸ“Š Output length: {len(result.get('output', []))}")
105
+
106
+ if result.get('mode') == 'fallback':
107
+ print(f" πŸ’‘ Note: {result.get('note', 'Running in fallback mode')}")
108
+ else:
109
+ print(f" 🎯 Full ECG-FM model inference completed!")
110
+
111
+ else:
112
+ print(f" ❌ Error: {r.text}")
113
+
114
+ except requests.exceptions.Timeout:
115
+ print(" ⏰ Timeout - Inference taking longer than expected")
116
+ except Exception as e:
117
+ print(f" ❌ Error: {e}")
118
+
119
+ print()
120
+ print("=" * 60)
121
+ print("🏁 Real ECG Testing Complete!")
122
+ print()
123
+ print("πŸ“Š Results Summary:")
124
+ print(" - If you see 200 status codes: API is working with real data!")
125
+ print(" - If you see fallback mode: API works but model not fully loaded")
126
+ print(" - If you see full mode: Complete ECG-FM inference working!")
127
+ print()
128
+ print("πŸ”— Your API is live at:")
129
+ print(f" {SPACE_URL}")
130
+ print()
131
+ print("πŸ“± Test manually:")
132
+ print(f" Health: {SPACE_URL}/healthz")
133
+ print(f" Root: {SPACE_URL}/")
134
+
135
+ if __name__ == "__main__":
136
+ test_api_with_real_ecg()