Spaces:
Runtime error
Runtime error
Commit ·
e87ec54
1
Parent(s): fef82a4
Fix confidence scores loading with absolute path
Browse files- Use absolute path to confidence_scores.js instead of relative path
- Add detailed debugging for file path resolution
- Add better error reporting for subprocess failures
- This should fix the issue with confidence scores not loading in HF Spaces
app.py
CHANGED
|
@@ -220,10 +220,18 @@ with open(CAT_MAPPINGS_SAVE_PATH, 'r') as f:
|
|
| 220 |
def load_confidence_scores():
|
| 221 |
"""Load confidence scores from the JavaScript file"""
|
| 222 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 223 |
result = subprocess.run([
|
| 224 |
'node', '-e',
|
| 225 |
-
'const conf = require("
|
| 226 |
-
], capture_output=True, text=True
|
| 227 |
|
| 228 |
if result.returncode == 0:
|
| 229 |
confidence_data = json.loads(result.stdout.strip())
|
|
@@ -231,9 +239,13 @@ def load_confidence_scores():
|
|
| 231 |
return confidence_data
|
| 232 |
else:
|
| 233 |
print(f"⚠️ Failed to load confidence scores: {result.stderr}")
|
|
|
|
|
|
|
| 234 |
return {}
|
| 235 |
except Exception as e:
|
| 236 |
print(f"⚠️ Error loading confidence scores: {e}")
|
|
|
|
|
|
|
| 237 |
return {}
|
| 238 |
|
| 239 |
# Load confidence scores
|
|
|
|
| 220 |
def load_confidence_scores():
|
| 221 |
"""Load confidence scores from the JavaScript file"""
|
| 222 |
try:
|
| 223 |
+
# Get the directory where this script is located
|
| 224 |
+
script_dir = os.path.dirname(os.path.abspath(__file__))
|
| 225 |
+
confidence_file = os.path.join(script_dir, 'confidence_scores.js')
|
| 226 |
+
|
| 227 |
+
print(f"📂 Script directory: {script_dir}")
|
| 228 |
+
print(f"📂 Looking for confidence file at: {confidence_file}")
|
| 229 |
+
print(f"📂 File exists: {os.path.exists(confidence_file)}")
|
| 230 |
+
|
| 231 |
result = subprocess.run([
|
| 232 |
'node', '-e',
|
| 233 |
+
f'const conf = require("{confidence_file}"); console.log(JSON.stringify(conf.confidenceMapping));'
|
| 234 |
+
], capture_output=True, text=True)
|
| 235 |
|
| 236 |
if result.returncode == 0:
|
| 237 |
confidence_data = json.loads(result.stdout.strip())
|
|
|
|
| 239 |
return confidence_data
|
| 240 |
else:
|
| 241 |
print(f"⚠️ Failed to load confidence scores: {result.stderr}")
|
| 242 |
+
print(f"⚠️ Return code: {result.returncode}")
|
| 243 |
+
print(f"⚠️ Stdout: {result.stdout}")
|
| 244 |
return {}
|
| 245 |
except Exception as e:
|
| 246 |
print(f"⚠️ Error loading confidence scores: {e}")
|
| 247 |
+
import traceback
|
| 248 |
+
traceback.print_exc()
|
| 249 |
return {}
|
| 250 |
|
| 251 |
# Load confidence scores
|