dylanebert commited on
Commit
93f66e7
·
1 Parent(s): c770c2e

fix json serialization

Browse files
Files changed (1) hide show
  1. app.py +21 -4
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import json
2
  from typing import Literal
 
3
 
4
  import gradio as gr
5
  from huggingface_hub import list_models, model_info, hf_hub_download
@@ -106,10 +107,10 @@ def get_model_info(model_id: str) -> dict:
106
  result["author"] = model.author
107
 
108
  if hasattr(model, "created_at") and model.created_at is not None:
109
- result["created_at"] = model.created_at
110
 
111
  if hasattr(model, "last_modified") and model.last_modified is not None:
112
- result["last_modified"] = model.last_modified
113
 
114
  if hasattr(model, "downloads") and model.downloads is not None:
115
  result["downloads"] = model.downloads
@@ -146,10 +147,26 @@ def get_model_info(model_id: str) -> dict:
146
  result["datasets"] = model.card_data.datasets
147
 
148
  if hasattr(model, "siblings") and model.siblings is not None:
149
- result["siblings"] = model.siblings
 
 
 
 
 
 
 
 
150
 
151
  if hasattr(model, "spaces") and model.spaces is not None:
152
- result["spaces"] = model.spaces
 
 
 
 
 
 
 
 
153
 
154
  if hasattr(model, "xet_enabled") and model.xet_enabled is not None:
155
  result["xet_enabled"] = model.xet_enabled
 
1
  import json
2
  from typing import Literal
3
+ from datetime import datetime
4
 
5
  import gradio as gr
6
  from huggingface_hub import list_models, model_info, hf_hub_download
 
107
  result["author"] = model.author
108
 
109
  if hasattr(model, "created_at") and model.created_at is not None:
110
+ result["created_at"] = str(model.created_at)
111
 
112
  if hasattr(model, "last_modified") and model.last_modified is not None:
113
+ result["last_modified"] = str(model.last_modified)
114
 
115
  if hasattr(model, "downloads") and model.downloads is not None:
116
  result["downloads"] = model.downloads
 
147
  result["datasets"] = model.card_data.datasets
148
 
149
  if hasattr(model, "siblings") and model.siblings is not None:
150
+ result["siblings"] = []
151
+ for s in model.siblings:
152
+ if isinstance(s, str):
153
+ result["siblings"].append(s)
154
+ else:
155
+ result["siblings"].append({
156
+ k: str(v) if isinstance(v, datetime) else v
157
+ for k, v in s.__dict__.items() if not k.startswith('_')
158
+ })
159
 
160
  if hasattr(model, "spaces") and model.spaces is not None:
161
+ result["spaces"] = []
162
+ for s in model.spaces:
163
+ if isinstance(s, str):
164
+ result["spaces"].append(s)
165
+ else:
166
+ result["spaces"].append({
167
+ k: str(v) if isinstance(v, datetime) else v
168
+ for k, v in s.__dict__.items() if not k.startswith('_')
169
+ })
170
 
171
  if hasattr(model, "xet_enabled") and model.xet_enabled is not None:
172
  result["xet_enabled"] = model.xet_enabled