import { Store, UIEventSource } from "../../Logic/UIEventSource" import { ProvidedImage } from "../../Logic/ImageProviders/ImageProvider" import Wikidata from "../../Logic/Web/Wikidata" import ChangeTagAction from "../../Logic/Osm/Actions/ChangeTagAction" import { And } from "../../Logic/Tags/And" import { Tag } from "../../Logic/Tags/Tag" import AllImageProviders from "../../Logic/ImageProviders/AllImageProviders" import { SpecialVisualizationState, SpecialVisualizationSvelte } from "../SpecialVisualization" import SvelteUIElement from "../Base/SvelteUIElement" import PlantNet from "../PlantNet/PlantNet.svelte" import { default as PlantNetCode } from "../../Logic/Web/PlantNet" import { ServerSourceInfo } from "../../Models/SourceOverview" export class PlantNetDetectionViz extends SpecialVisualizationSvelte { funcName = "plantnet_detection" needsUrls: ServerSourceInfo[] = [{ url : PlantNetCode.baseUrl, description: "Planet provides an API that, based on images, detects a plant species", category: "feature", openData: true, selfhostable: "unknown", trigger:["specific_feature", "specific_theme", "clear_consent"], moreInfo: ["https://plantnet.org","https://github.com/plantnet"] }] group = "data_import" docs = "Sends the images linked to the current object to plantnet.org and asks it what plant species is shown on it. The user can then select the correct species; the corresponding wikidata-identifier will then be added to the object (together with `source:species:wikidata=plantnet.org AI`). " args = [ { name: "image_key", defaultValue: AllImageProviders.defaultKeys.join(","), doc: "The keys given to the images, e.g. if image is given, the first picture URL will be added as image, the second as image:0, the third as image:1, etc... Multiple values are allowed if ';'-separated ", }, ] public constr( state: SpecialVisualizationState, tags: UIEventSource>, args: string[] ): SvelteUIElement { let imagePrefixes: string[] = undefined if (args.length > 0) { imagePrefixes = [].concat(...args.map((a) => a.split(","))) } const allProvidedImages: Store = AllImageProviders.loadImagesFor( tags, imagePrefixes ) const imageUrls: Store = allProvidedImages.map((pi) => pi.map((pi) => pi.url)) async function applySpecies(selectedWikidata) { selectedWikidata = Wikidata.ExtractKey(selectedWikidata) const change = new ChangeTagAction( tags.data.id, new And([ new Tag("species:wikidata", selectedWikidata), new Tag("source:species:wikidata", "PlantNet.org AI"), ]), tags.data, { theme: state.theme.id, changeType: "plantnet-ai-detection", } ) await state.changes.applyAction(change) } return new SvelteUIElement(PlantNet, { imageUrls, onConfirm: applySpecies }) } }