{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# SynthScope quickstart\n", "\n", "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/SMSD75/SynthScope/blob/main/notebooks/synthscope_quickstart.ipynb)\n", "\n", "Run state-of-the-art **AI-generated image & video detectors** in a few lines with the [`synthscope`](https://github.com/SMSD75/SynthScope) library.\n", "\n", "> Tip: switch the runtime to a **GPU** (Runtime \u2192 Change runtime type) \u2014 the backbones are large." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Install\n", "\n", "Installs `synthscope` (which pulls PyTorch, transformers, etc.) and OpenAI CLIP (needed by a couple of detectors). Takes a few minutes on first run." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "%pip install -q \"git+https://github.com/SMSD75/SynthScope.git\" \"git+https://github.com/openai/CLIP.git\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2. Get detector weights\n", "\n", "This notebook uses **CuRe**, whose authors publish their weights on GitHub (a 25 MB adapter). The first prediction also downloads the frozen PE-Core backbone (2.7 GB) from Hugging Face. Other detectors need their weights as `.pth` in the same folder; each model's README links the official download." ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "import os, urllib.request\n", "\n", "CKPT = \"/content/synthscope_ckpts\" if os.path.isdir(\"/content\") else os.path.expanduser(\"~/synthscope_ckpts\")\n", "os.makedirs(CKPT, exist_ok=True)\n", "os.environ[\"SYNTHSCOPE_CKPT_DIR\"] = CKPT # must be set before importing synthscope\n", "\n", "if not os.path.exists(f\"{CKPT}/cure.pth\"):\n", " urllib.request.urlretrieve(\n", " \"https://raw.githubusercontent.com/manic-cui/CuRe/main/weights/cure_adapter.pt\", f\"{CKPT}/cure.pth\")\n", "\n", "import synthscope\n", "[m[\"key\"] for m in synthscope.list_models() if m[\"available\"]] # detectors that can run here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3. Upload an image (or video)" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "try:\n", " from google.colab import files\n", " uploaded = files.upload()\n", " path = next(iter(uploaded))\n", "except Exception:\n", " path = \"your_image.png\" # running outside Colab: set a local path\n", "print(\"file:\", path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4. Detect" ] }, { "cell_type": "code", "metadata": {}, "execution_count": null, "outputs": [], "source": [ "det = synthscope.load(\"cure\")\n", "result = det.predict(path)\n", "print(f\"Verdict: {result['verdict'].upper()} | P(AI-generated) = {result['fake_probability']:.3f}\")\n", "result" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Next steps\n", "\n", "- Add more detectors: put their weights in the `CKPT` folder as `.pth` (see each model's README), then `synthscope.load(key)`.\n", "- Training-free video detectors need no weights: `synthscope.load('d3').predict('clip.mp4')`.\n", "- Use your own trained checkpoint: `synthscope.load('cnn', checkpoint='/path/to.pth')`.\n", "- See the [repo](https://github.com/SMSD75/SynthScope) for the web demo, the benchmarks (datasets download themselves), and how to add a detector." ] } ], "metadata": { "accelerator": "GPU", "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }