Skip to content

Commit

Permalink
Added the service class method to the modelcard
Browse files Browse the repository at this point in the history
  • Loading branch information
Malikbadmus committed Jun 25, 2024
1 parent 9ace45e commit b6bd979
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 4 deletions.
22 changes: 20 additions & 2 deletions ersilia/hub/content/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
except:
Hdf5Explorer = None

from ...default import CARD_FILE, METADATA_JSON_FILE
from ...default import CARD_FILE, METADATA_JSON_FILE, SERVICE_CLASS_FILE


class BaseInformation(ErsiliaBase):
Expand Down Expand Up @@ -714,7 +714,18 @@ def get(self, model_id):
return card
else:
return None


def get_service_class(self, model_id):
service_class_path = os.path.join(
self._get_bundle_location(model_id), SERVICE_CLASS_FILE
)

if os.path.exists(service_class_path):
with open(service_class_path, "r") as f:
service_class = f.read().strip()
return service_class
else:
return None

class LakeCard(ErsiliaBase):
def __init__(self, config_json=None):
Expand Down Expand Up @@ -760,3 +771,10 @@ def get(self, model_id, as_json=False):
return json.dumps(card, indent=4)
else:
return card

def service_class(self, model_id, as_json=False):
service = self.lc.get_service_class(model_id)
if service is None:
return
else:
return service
29 changes: 27 additions & 2 deletions ersilia/hub/content/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,27 @@ def _get_slug(self, card):
return card["Slug"]
return None

def _get_status(self, card):
if "status" in card:
return card["status"]
if "Status" in card:
return card["Status"]
return None

def _get_input(self, card):
if "input" in card:
return card["input"][0]
if "Input" in card:
return card["Input"][0]
return None

def _get_output(self, card):
if "output" in card:
return card["output"][0]
if "Output" in card:
return card["Output"][0]
return None

def airtable(self):
"""List models available in AirTable Ersilia Model Hub base"""
if webbrowser:
Expand Down Expand Up @@ -173,8 +194,12 @@ def local(self):
card = mc.get(model_id)
slug = self._get_slug(card)
title = self._get_title(card)
R += [[model_id, slug, title]]
columns = ["Identifier", "Slug", "Title"]
status = self._get_status(card)
inputs = self._get_input(card)
output = self._get_output(card)
service_class = mc.service_class(model_id)
R += [[model_id, slug, title, status, inputs, output, service_class]]
columns = ["Identifier", "Slug", "Title", "Status", "Input", "Output", "Service Class"]
logger.info("Found {0} models".format(len(R)))
if len(R) == 0:
return None
Expand Down

0 comments on commit b6bd979

Please sign in to comment.