Code Monkey home page Code Monkey logo

magic-copy's Introduction

Magic Copy

Magic Copy is a Chrome extension that uses Meta's Segment Anything Model to extract a foreground object from an image and copy it to the clipboard.

Untitled.video.-.Made.with.Clipchamp.1.mp4

Installation

Available on the Chrome Web Store

Available on the Firefox Add-ons Store

(This might not be available yet, as the extension is still in review.)

Alternatively, the extension can be installed manually:

  1. Download the latest magic-copy.zip from releases.
  2. Extract the ZIP file.
  3. In Chrome, go to chrome://extensions/, enable "Developer mode", and click "Load unpacked".
  4. Select the folder where the extension was extracted.

Implementation

This extension uses the same procedure as the Segment Anything Model demo to extract a foreground object from an image. The only difference is that the extracted object is copied to the clipboard instead of being displayed on the page.

Building

Manually

Build the extension with npm and then run the included ./buildcrx.sh script to generate the crx file:

npm ci
npm run build
./buildcrx.sh -d dist

Docker

A Dockerfile is provided to cleanly build the crx file. To build the extension, run:

docker build --output out .

Self-hosting

The Meta Segment Anything Model requires running the vision transformer on a server to generate the image's embeddings. Magic Copy uses the same service that their demo uses, however some people may not want to send their images to a third party.

The server-example directory contains a simple example of how to self-host the vision transformer service. It is not meant to be used in production, but rather as a proof of concept to document the input/output format of the service.

In particular, Magic Copy (and the SAM demo) expect a POST endpoint that accepts an image file and returns a JSON array of length 1 with the embedding of shape (1, 256, 64, 64) as a base64 encoded string. See the code for specific details on how to perform this encoding to be compatible with the demo.

If you are looking to quickly get the service running, you can use the provided Dockerfile to build a container and run it. The container will expose port 8000 and will serve the service at the / endpoint.

docker build -t segment-anything .
docker run --gpus all -p 8000:8000 segment-anything

In the Magic Copy chrome extension, you can then change the endpoint to http://localhost:8000/.

magic-copy's People

Contributors

dependabot[bot] avatar kevmo314 avatar

Watchers

 avatar

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.