Spaces:
Running on Zero
Running on Zero
DASH Gaming commited on
Commit ·
31bcfe0
1
Parent(s): 5bf4177
Fix: Uvicorn launch configuration and robust JSON parsing for Firebase config
Browse filesFiles changed (2)
- app.py+7
- firebase_config.py+13-11
440 unmodified lines441442443440 unmodified linesexcept Exception as e:return JSONResponse(status_code=500, content={"error": str(e), "traceback": traceback.format_exc()})440 unmodified lines441442443444445446447448449450440 unmodified linesexcept Exception as e:return JSONResponse(status_code=500, content={"error": str(e), "traceback": traceback.format_exc()})# ---------------------------------------------------------------------------# Launch server — HF Spaces requires the app to bind on port 7860# ---------------------------------------------------------------------------import uvicornuvicorn.run(app, host="0.0.0.0", port=7860)
20 unmodified lines21222324252627282930313233343536373820 unmodified linesenv_key = env_key[1:-1]try:key_dict = json.loads(env_key)except Exception as e:# Try to handle potential double-escaped formattingtry:# Replace double-escaped newlines to single newlinesfixed_key = env_key.replace('\\\\n', '\\n').replace('\\n', '\n')key_dict = json.loads(fixed_key)except Exception:print(f"First-pass JSON parsing failed: {e}")# If still failing, try replacing newlines to space in outer JSON structural layoutcleaned_key = env_key.replace('\n', ' ').replace('\r', ' ')key_dict = json.loads(cleaned_key)# Make sure the private_key field is correctly formatted with single newlinesif isinstance(key_dict, dict) and "private_key" in key_dict:20 unmodified lines212223242526272829303132333435363738394020 unmodified linesenv_key = env_key[1:-1]try:key_dict = json.loads(env_key, strict=False)except Exception as e1:try:import astkey_dict = ast.literal_eval(env_key)except Exception as e2:try:# Try replacing single backslashes that aren't escaping valid JSON chars# (this often happens if users paste without proper escaping)fixed_key = env_key.replace('\\n', '\\\\n')key_dict = json.loads(fixed_key, strict=False)except Exception as e3:print(f"JSON parsing failed. E1: {e1}, E2: {e2}")raise e3# Make sure the private_key field is correctly formatted with single newlinesif isinstance(key_dict, dict) and "private_key" in key_dict:
app.py+7
firebase_config.py+13-11