xhluca commited on
Commit
b4446ee
1 Parent(s): 9d85624

Improve error message

Browse files
Files changed (2) hide show
  1. app.py +10 -2
  2. utils.py +6 -4
app.py CHANGED
@@ -138,7 +138,7 @@ def load_recording(basedir):
138
  replay_file = replay_file.replace(".json", "")
139
 
140
  if not Path(basedir).joinpath('metadata.json').exists():
141
- st.sidebar.error(f"Metadata file not found at {basedir}/metadata.json. This is likely an issue with Huggingface Spaces. Try cloning this repo and running locally.")
142
  st.stop()
143
 
144
  metadata = load_json_no_cache(basedir, "metadata")
@@ -157,7 +157,15 @@ def load_recording(basedir):
157
 
158
  # Read in the JSON data
159
  replay_dict = load_json_no_cache(basedir, replay_file)
160
- form = load_json(basedir, "form")
 
 
 
 
 
 
 
 
161
 
162
  duration = replay_dict["data"][-1]["timestamp"] - replay_dict["data"][0]["timestamp"]
163
  duration = time.strftime("%M:%S", time.gmtime(duration))
 
138
  replay_file = replay_file.replace(".json", "")
139
 
140
  if not Path(basedir).joinpath('metadata.json').exists():
141
+ st.error(f"Metadata file not found at {basedir}/metadata.json. This is likely an issue with Huggingface Spaces. Try cloning this repo and running locally.")
142
  st.stop()
143
 
144
  metadata = load_json_no_cache(basedir, "metadata")
 
157
 
158
  # Read in the JSON data
159
  replay_dict = load_json_no_cache(basedir, replay_file)
160
+ form = load_json_no_cache(basedir, "form")
161
+
162
+ if replay_dict is None:
163
+ st.error(f"Replay file not found at {basedir}/{replay_file}. This is likely an issue with Huggingface Spaces. Try cloning this repo and running locally.")
164
+ st.stop()
165
+
166
+ if form is None:
167
+ st.error(f"Form file not found at {basedir}/form.json. This is likely an issue with Huggingface Spaces. Try cloning this repo and running locally.")
168
+ st.stop()
169
 
170
  duration = replay_dict["data"][-1]["timestamp"] - replay_dict["data"][0]["timestamp"]
171
  duration = time.strftime("%M:%S", time.gmtime(duration))
utils.py CHANGED
@@ -37,10 +37,12 @@ def load_json(basedir, name):
37
  def load_json_no_cache(basedir, name):
38
  if not os.path.exists(f"{basedir}/{name}.json"):
39
  return None
40
-
41
- with open(f"{basedir}/{name}.json", "r") as f:
42
- j = json.load(f)
43
-
 
 
44
  return j
45
 
46
 
 
37
  def load_json_no_cache(basedir, name):
38
  if not os.path.exists(f"{basedir}/{name}.json"):
39
  return None
40
+ try:
41
+ with open(f"{basedir}/{name}.json", "r") as f:
42
+ j = json.load(f)
43
+ except:
44
+ return None
45
+
46
  return j
47
 
48