Giter Site home page Giter Site logo

egardner / mediawiki-extensions-machinevision Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 1.1 MB

[WIP] Fork of the MediaWiki MachineVision extension using Vue.js

License: GNU General Public License v2.0

PHP 47.45% JavaScript 31.79% CSS 5.62% Vue 15.10% Shell 0.03%

mediawiki-extensions-machinevision's Introduction

mediawiki-extensions-MachineVision

This extension will support collecting data about images from internal and external machine vision services, storing it for on-wiki usage, and serving it for editor verification.

For details, see the project page on mediawiki.org.

Installation

Download and enable the extension

  1. Clone the extension repo into the extensions directory of your local MediaWiki installation: git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/MachineVision"
  2. Run composer install in the MachineVision directory
  3. Add wfLoadExtension( 'MachineVision' ); to your LocalSettings.php file
  4. Run php maintenance/update.php in your top-level MediaWiki directory

Import a mapping file

This extension will eventually support other providers, but for now testing and development will be done using the Google Cloud Vision API. To map Freebase objects (used by this API) to Wikidata entities (used by this extension), download the Freebase/Wikidata Mappings file from Google at the below URL:

https://developers.google.com/freebase/#freebase-wikidata-mappings

Extract the downloaded file from its archive and place it somewhere that MediaWiki can access it. To import, run the following maintenance script:

# in the mediawiki/extensions/MachineVision directory
php maintenance/populateFreebaseMapping.php --mappingFile path_to_your_file.nt

This process may take some time to complete.

Configuration and Usage

Configuration

For local development, use the following settings in LocalSettings.php if using the Google Cloud Vision API:

$wgMachineVisionRequestLabelsOnUploadComplete = true;
$wgMachineVisionRequestLabelsFromWikidataPublicApi = true;
$wgMachineVisionGCVSendFileContents = true;

$wgMachineVisionHandlers['google'] = [
	'class' => MediaWiki\Extension\MachineVision\Handler\GoogleCloudVisionHandler::class,
	'services' => [
		'MachineVisionFetchGoogleCloudVisionAnnotationsJobFactory',
		'MachineVisionRepository',
		'MachineVisionRepoGroup',
		'MachineVisionLabelResolver',
	],
];

If testing filtering criteria for the Computer-Aided Tagging feature, you may want to set some SafeSearch limits:

$wgMachineVisionGoogleSafeSearchLimits = [
	'adult' => 3,
	'medical' => 3,
	'violent' => 4,
	'racy' => 4,
];

Finally, to test submitting tags for an image locally, you will need to hardcode an entity ID in the onFinalConfirm() method of the ImageWithSuggestionsWidget component. Set it to an item that exists on your local instance, e.g.:

	new datamodel.Claim(
		new datamodel.PropertyValueSnak(
			depictsPropertyId,
	-       new datamodel.EntityId( widget.suggestionData.wikidataId )
	+       new datamodel.EntityId( 'Q1' )
		),
		null, // qualifiers
		self.guidGenerator.newGuid()
	)

Google API Credentials

To use the Google Cloud Vision with this extension, you will need to have valid Google Cloud credentials. You will need to sign up for a free trial at: https://console.cloud.google.com and generate credentials for the Google Cloud Vision service. Download a JSON file with your credentials from the dashboard and place it somewhere accessible to the web server that is running MediaWiki. You will need to provide a path to this file as an extension configuration setting in LocalSettings.php:

$wgMachineVisionGoogleCredentialsFileLocation = '/var/www/mediawiki/machine-vision-credentials.json';

Usage

Log in and upload a file (after $wgMachineVisionRequestLabelsOnUploadComplete has been set to true). This will enqueue an image annotation job in the MediaWiki job queue. After the job runs, navigate to Special:SuggestedTags to see suggested tags from Google.

Note

When and how often jobs run depends on your local configuration; see https://www.mediawiki.org/wiki/Manual:Job_queue for details. You can always run all jobs in the job queue manually by executing maintenance/runJobs.php.

Working with LESS variables

Since Wikimedia UI base variables aren't in core, we require them as a package dependency, then use a shell script to copy them to the lib directory. To update the base variables, require the new version in package.json and install it, then run npm run build-lib to copy the updated file into lib. Commit the updated files.

We're including the base variables in our custom variables file, resources/style-variables.less. To use them in other files, include style-variables.less rather than directly including the base file itself.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.