Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the service class method to the modelcard #1173

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 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,23 @@ def get(self, model_id):
return card
else:
return None


def get_service_class(self, model_id):
DhanshreeA marked this conversation as resolved.
Show resolved Hide resolved
"""
This method returns information about how the model was fetched by reading
the service class file located in the model's bundle directory. If the service
class file does not exist, it returns None.
"""
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 +776,10 @@ def get(self, model_id, as_json=False):
return json.dumps(card, indent=4)
else:
return card

def get_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.get_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