Skip to content

Commit

Permalink
keep improving the API
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Aug 7, 2024
1 parent d6fc080 commit b4c8e89
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 44 deletions.
3 changes: 3 additions & 0 deletions src/main/java/ai/nets/samj/communication/model/SAMModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.IOException;
import java.util.List;

import ai.nets.samj.install.SamEnvManagerAbstract;
import ai.nets.samj.ui.SAMJLogger;
import net.imglib2.Interval;
import net.imglib2.Localizable;
Expand Down Expand Up @@ -60,6 +61,8 @@ public interface SAMModel {
* @return a text describing the model.
*/
String getDescription();

SamEnvManagerAbstract getInstallationManger();
/**
*
* @return true or false whether all the things needed to run the model are already installed or not.
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/ai/nets/samj/gui/SAMJDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
import ai.nets.samj.gui.icons.ButtonIcon;
import ai.nets.samj.gui.icons.LoadingButton;
import ai.nets.samj.gui.tools.Tools;
import ai.nets.samj.install.SamEnvManagerAbstract;
import ai.nets.samj.ui.PromptsResultsDisplay;
import ai.nets.samj.ui.PromptsResultsDisplay.SAMJException;
import ai.nets.samj.ui.SAMJLogger;
import ai.nets.samj.ui.UtilityMethods;
import ai.nets.samj.install.SamEnvManager;

/**
* Class that creates a default graphical user interface to interact with SAMJ models
Expand Down Expand Up @@ -350,9 +350,9 @@ public void setPromptsProvider(PromptsFunctionalInterface pp) {

/**
*
* @return the {@link SamEnvManager} used to install and mange the models
* @return the {@link SamEnvManager} used to install and manage the models
*/
public SamEnvManager getModelInstallationManager() {
public SamEnvManagerAbstract getModelInstallationManager() {
return this.panelModel.getInstallationManager();
}

Expand Down
46 changes: 5 additions & 41 deletions src/main/java/ai/nets/samj/gui/SAMModelPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
import ai.nets.samj.gui.components.GridPanel;
import ai.nets.samj.gui.components.HTMLPane;
import ai.nets.samj.gui.tools.Files;
import ai.nets.samj.install.SamEnvManagerAbstract;
import io.bioimage.modelrunner.apposed.appose.Mamba;
import ai.nets.samj.install.SamEnvManager;

/**
* Class that creates a subpanel in the main panel of SAMJ default GUI.
Expand Down Expand Up @@ -97,10 +97,6 @@ public class SAMModelPanel extends JPanel implements ActionListener {
* Object contianing a list of the models available, and whether they are selected, installed...
*/
private SAMModels models;
/**
* Object that manages the models and their installation
*/
private final SamEnvManager manager;
/**
* Index of hte selected model in the list of available models
*/
Expand Down Expand Up @@ -150,7 +146,6 @@ interface CallParent {
public SAMModelPanel(SAMModels models, CallParent updateParent) {
super();
this.updateParent = updateParent;
manager = SamEnvManager.create((str) -> addHtml(str));
this.models = models;
JToolBar pnToolbarModel = new JToolBar();
pnToolbarModel.setFloatable(false);
Expand Down Expand Up @@ -208,25 +203,7 @@ private void checkInstalledModelsThread() {
}
for(SAMModel model : models) {
if (Thread.currentThread().isInterrupted()) return;
if (model.getName().equals(EfficientSAM.FULL_NAME))
model.setInstalled(manager.checkEfficientSAMPythonInstalled()
&& manager.checkEfficientSAMSmallWeightsDownloaded()
&& manager.checkEfficientSAMPackageInstalled());
else if (model.getName().equals(EfficientViTSAML0.FULL_NAME))
model.setInstalled(manager.checkEfficientViTSAMPythonInstalled()
&& manager.checkEfficientViTSAMPackageInstalled() && manager.checkEfficientViTSAMWeightsDownloaded("l0"));
else if (model.getName().equals(EfficientViTSAML1.FULL_NAME))
model.setInstalled(manager.checkEfficientViTSAMPythonInstalled()
&& manager.checkEfficientViTSAMPackageInstalled() && manager.checkEfficientViTSAMWeightsDownloaded("l1"));
else if (model.getName().equals(EfficientViTSAML2.FULL_NAME))
model.setInstalled(manager.checkEfficientViTSAMPythonInstalled()
&& manager.checkEfficientViTSAMPackageInstalled() && manager.checkEfficientViTSAMWeightsDownloaded("l2"));
else if (model.getName().equals(EfficientViTSAMXL0.FULL_NAME))
model.setInstalled(manager.checkEfficientViTSAMPythonInstalled()
&& manager.checkEfficientViTSAMPackageInstalled() && manager.checkEfficientViTSAMWeightsDownloaded("xl0"));
else if (model.getName().equals(EfficientViTSAMXL1.FULL_NAME))
model.setInstalled(manager.checkEfficientViTSAMPythonInstalled()
&& manager.checkEfficientViTSAMPackageInstalled() && manager.checkEfficientViTSAMWeightsDownloaded("xl1"));
model.setInstalled(model.getInstallationManger().checkEverythingInstalled());
}

if (isEDT) {
Expand Down Expand Up @@ -288,8 +265,8 @@ public SAMModel getSelectedModel() {
*
* @return the installation manager
*/
public SamEnvManager getInstallationManager() {
return this.manager;
public SamEnvManagerAbstract getInstallationManager() {
return this.models.get(selectedModel).getInstallationManger();
}

/**
Expand All @@ -307,20 +284,7 @@ private void createInstallationThread() {
this.installationThread = new Thread(() -> {
try {
SwingUtilities.invokeLater(() -> installationInProcess(true));
if (getSelectedModel().getName().equals(EfficientSAM.FULL_NAME))
this.manager.installEfficientSAMSmall();
else if (getSelectedModel().getName().equals(EfficientViTSAML0.FULL_NAME))
this.manager.installEfficientViTSAM("l0");
else if (getSelectedModel().getName().equals(EfficientViTSAML1.FULL_NAME))
this.manager.installEfficientViTSAM("l1");
else if (getSelectedModel().getName().equals(EfficientViTSAML2.FULL_NAME))
this.manager.installEfficientViTSAM("l2");
else if (getSelectedModel().getName().equals(EfficientViTSAMXL0.FULL_NAME))
this.manager.installEfficientViTSAM("xl0");
else if (getSelectedModel().getName().equals(EfficientViTSAMXL1.FULL_NAME))
this.manager.installEfficientViTSAM("xl1");
else
throw new RuntimeException();
this.getSelectedModel().getInstallationManger().installEverything();
getSelectedModel().setInstalled(true);
SwingUtilities.invokeLater(() -> {
installationInProcess(false);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/ai/nets/samj/install/SamEnvManagerAbstract.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ public abstract class SamEnvManagerAbstract {
final static public String DEFAULT_DIR = new File("appose_x86_64").getAbsolutePath();


public abstract boolean checkEverythingInstalled();

public abstract boolean checkSAMDepsInstalled();

public abstract void installSAMDeps() throws IOException, InterruptedException, ArchiveException, URISyntaxException, MambaInstallException;
Expand All @@ -106,6 +108,8 @@ public abstract class SamEnvManagerAbstract {

public abstract String getModelEnv();

public abstract void uninstall();




Expand Down

0 comments on commit b4c8e89

Please sign in to comment.