incoming??
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $MarketplaceItem : Adw.ActionRow {
|
||||
activatable-widget: download;
|
||||
[suffix]
|
||||
Button download {
|
||||
styles ["flat"]
|
||||
valign: center;
|
||||
icon-name: "folder-download-symbolic";
|
||||
tooltip-text: _("Download Model");
|
||||
clicked => $on_download_button_clicked();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
from gi.repository import Gtk, Adw, GLib
|
||||
|
||||
from bavarder.constants import app_id, rootdir
|
||||
from bavarder.threading import KillableThread
|
||||
|
||||
|
||||
@Gtk.Template(resource_path=f"{rootdir}/ui/marketplace_item.ui")
|
||||
class MarketplaceItem(Adw.ActionRow):
|
||||
__gtype_name__ = "MarketplaceItem"
|
||||
|
||||
def __init__(self, app, window, model_info, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.app = app
|
||||
self.window = window
|
||||
self.model_info = model_info
|
||||
|
||||
self.setup()
|
||||
|
||||
def setup(self):
|
||||
self.set_title(self.model_info.get("name", ""))
|
||||
self.set_subtitle(self.model_info.get("id", ""))
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def on_download_button_clicked(self, widget, *args):
|
||||
def thread_run():
|
||||
self.app.action_running_in_background = True
|
||||
|
||||
toast = Adw.Toast()
|
||||
toast.set_timeout(0)
|
||||
toast.set_title(_("Downloading model %s" % self.model_info.get("name")))
|
||||
self.window.add_toast(toast)
|
||||
|
||||
model_id = self.model_info.get("id")
|
||||
from huggingface_hub import hf_hub_download
|
||||
model_file = hf_hub_download(
|
||||
repo_id=model_id,
|
||||
filename="*.litertlm",
|
||||
cache_dir=self.app.user_cache_dir
|
||||
)
|
||||
|
||||
self.app.data["providers"]["litert-lm"]["data"]["model_path"] = model_file
|
||||
self.app.data["providers"]["litert-lm"]["data"]["hf_model"] = model_id
|
||||
GLib.idle_add(cleanup, toast, model_file)
|
||||
|
||||
def cleanup(toast, model_file):
|
||||
t.join()
|
||||
|
||||
toast.dismiss()
|
||||
|
||||
self.app.action_running_in_background = False
|
||||
|
||||
toast = Adw.Toast()
|
||||
toast.set_title(_("Model %s downloaded!" % self.model_info.get("name")))
|
||||
self.window.add_toast(toast)
|
||||
|
||||
t = KillableThread(target=thread_run)
|
||||
t.start()
|
||||
Reference in New Issue
Block a user