Skip to content

Commit

Permalink
correct model download
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosuc3m committed Aug 6, 2024
1 parent 9224b7b commit c418a1d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import io.bioimage.modelrunner.bioimageio.description.ModelDescriptorFactory;
import io.bioimage.modelrunner.bioimageio.download.DownloadModel;
import io.bioimage.modelrunner.bioimageio.download.DownloadTracker;
import io.bioimage.modelrunner.utils.Constants;
import io.bioimage.modelrunner.utils.Log;

/**
Expand Down Expand Up @@ -652,12 +653,18 @@ public String getModelRdfUrl(String id, String version) {

if (modelsInfo.get(id) == null)
return null;
String rdfURL;
if (version == null) {
return modelsInfo.get(id).values().stream()
rdfURL = modelsInfo.get(id).values().stream()
.filter(val -> val.get("latest").equals("true")).findFirst().get().get("source");
} else if (version != null && modelsInfo.get(id).get(version) != null) {
rdfURL = modelsInfo.get(id).get(version).get("source");
} else {
return null;
}
if (rdfURL == null) return null;

return modelsInfo.get(id).get(version).get("source");
return rdfURL.substring(0, rdfURL.length() - Constants.RDF_FNAME.length());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ public interface ModelDescriptor {
*/
public String getName();

/**
* @return The nickname of this model.
*/
public String getNickname();

/**
* @return The ID of this model.
*/
Expand Down Expand Up @@ -205,11 +200,6 @@ public static TensorSpec findTensorInList(String name, List<TensorSpec> tts)
*/
public Map<String, Object> getAttachments();

/**
* @return the download_url
*/
public String getDownloadUrl();

/**
* @return the rdf_source
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
import java.util.Set;
import java.util.stream.Collectors;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;

import io.bioimage.modelrunner.bioimageio.BioimageioRepo;
import io.bioimage.modelrunner.bioimageio.description.exceptions.ModelSpecsException;
import io.bioimage.modelrunner.bioimageio.description.weights.ModelWeight;
import io.bioimage.modelrunner.utils.Log;
import io.bioimage.modelrunner.utils.Constants;


/**
Expand Down Expand Up @@ -80,6 +76,8 @@ public class ModelDescriptorV04 implements ModelDescriptor
private String modelID;
private String localModelPath;
private boolean supportBioengine = false;

private static BioimageioRepo BMZ_REPO;

private ModelDescriptorV04()
{
Expand Down Expand Up @@ -700,20 +698,6 @@ public Map<String, Object> getAttachments() {
return attachments;
}

/**
* @return the download_url
*/
public String getDownloadUrl() {
return download_url;
}

/**
* @return the rdf_source
*/
public String getRDFSource() {
return rdf_source;
}

/**
* @return the version
*/
Expand Down Expand Up @@ -818,26 +802,20 @@ public void addModelPath(Path modelBasePath) {
// TODO Auto-generated method stub

}

private void findDownloadURL() {
String text = BioimageioRepo.getJSONFromUrl(BioimageioRepo.location);
if (text == null) {
return;
}
JsonObject json = null;
try {
json = (JsonObject) JsonParser.parseString(text);
List<JsonElement> entries = json.get("entries").getAsJsonArray().asList();
entries.stream()
} catch (Exception ex) {
return;
}
}

@Override
public String getModelURL() {
if (this.download_url == null && BMZ_REPO == null) {
BMZ_REPO = BioimageioRepo.connect();
}

if (this.download_url == null)
findDownloadURL();
return download_url;
this.download_url = BMZ_REPO.getModelRdfUrl(modelID, version);
return this.download_url;
}

@Override
public String getRDFSource() {
return getModelURL() + Constants.RDF_FNAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.bioimage.modelrunner.bioimageio.BioimageioRepo;
import io.bioimage.modelrunner.bioimageio.description.exceptions.ModelSpecsException;
import io.bioimage.modelrunner.bioimageio.description.weights.ModelWeight;
import io.bioimage.modelrunner.utils.Constants;


/**
Expand All @@ -44,9 +45,11 @@ public class ModelDescriptorV05 implements ModelDescriptor
{
private String format_version;
private String name;
private String download_url;
private String timestamp;
private String description;
private String type;
private String git_repo;
private List<Author> authors;
private List<Author> maintainers;
private List<Author> packaged_by;
Expand All @@ -69,6 +72,8 @@ public class ModelDescriptorV05 implements ModelDescriptor
private String localModelPath;
private boolean supportBioengine = false;
private Map<String, Object> yamlElements;

private static BioimageioRepo BMZ_REPO;

protected ModelDescriptorV05(Map<String, Object> yamlElements) throws ModelSpecsException
{
Expand Down Expand Up @@ -137,6 +142,9 @@ protected void buildModelDescription() throws ModelSpecsException
case "documentation":
documentation = (String) fieldElement;
break;
case "git_repo":
git_repo = (String) fieldElement;
break;
case "type":
type = (String) fieldElement;
break;
Expand Down Expand Up @@ -638,45 +646,35 @@ public String buildInfo() {
return null;
}

@Override
public String getNickname() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getGitRepo() {
// TODO Auto-generated method stub
return null;
return this.git_repo;
}

@Override
public List<Badge> getBadges() {
// TODO Auto-generated method stub
return null;
}

@Override
public String getDownloadUrl() {
// TODO Auto-generated method stub
return null;
return new ArrayList<Badge>();
}

@Override
public String getRDFSource() {
public void addModelPath(Path modelBasePath) {
// TODO Auto-generated method stub
return null;

}

@Override
public void addModelPath(Path modelBasePath) {
// TODO Auto-generated method stub
public String getModelURL() {
if (this.download_url == null && BMZ_REPO == null) {
BMZ_REPO = BioimageioRepo.connect();
}

if (this.download_url == null)
this.download_url = BMZ_REPO.getModelRdfUrl(modelID, version);
return this.download_url;
}

@Override
public String getModelURL() {
// TODO Auto-generated method stub
return null;
public String getRDFSource() {
return getModelURL() + Constants.RDF_FNAME;
}
}

0 comments on commit c418a1d

Please sign in to comment.