Skip to content

Commit

Permalink
Make huggingface[cli] and omlmd optional
Browse files Browse the repository at this point in the history
Fixes: #211

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Oct 1, 2024
1 parent e5dc9b3 commit 27a05bf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name = "ramalama"
version = "0.0.6"
dependencies = [
"argcomplete",
"omlmd",
"huggingface_hub[cli]",
]
requires-python = ">= 3.8"
maintainers = [
Expand Down
37 changes: 32 additions & 5 deletions ramalama/huggingface.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import os
from ramalama.common import run_cmd, exec_cmd
from ramalama.common import run_cmd, exec_cmd, perror
from ramalama.model import Model

missing_hugginface="""
Huggingface models requires the huggingface-cli and tldm modules.
These modules can be installed via:
pip install huggingface_hub[cli] tldm
"""

def download(store, model, directory, filename):
return run_cmd(
Expand All @@ -19,8 +24,13 @@ def download(store, model, directory, filename):


def try_download(store, model, directory, filename):
proc = download(store, model, directory, filename)
return proc.stdout.decode("utf-8")
try:
proc = download(store, model, directory, filename)
return proc.stdout.decode("utf-8")
except FileNotFoundError as e:
raise NotImplementedError("""\
%s
%s""" % (str(e).strip("'"), missing_hugginface))


class Huggingface(Model):
Expand All @@ -32,14 +42,21 @@ def login(self, args):
conman_args = ["huggingface-cli", "login"]
if args.token:
conman_args.extend(["--token", args.token])
exec_cmd(conman_args)
try:
self.exec(conman_args)
except FileNotFoundError as e:
raise NotImplementedError("""\
%s
%s
""" % str(e).strip("'"), missing_hugginface)

def logout(self, args):
conman_args = ["huggingface-cli", "logout"]
if args.token:
conman_args.extend(["--token", args.token])
conman_args.extend(args)
exec_cmd(conman_args)
self.exec(conman_args)

def pull(self, args):
split = self.model.rsplit("/", 1)
Expand Down Expand Up @@ -73,3 +90,13 @@ def get_symlink_path(self, args):
filename = split[0]

return f"{args.store}/models/huggingface/{directory}/{filename}"

def exec(self, args):
try:
exec_cmd(args)
except FileNotFoundError as e:
raise NotImplementedError("""\
%s
%s
""" % str(e).strip("'"), missing_hugginface)

0 comments on commit 27a05bf

Please sign in to comment.