← back to Animate Museum Posts

test-all-services.js

146 lines

import fs from 'fs';
import path from 'path';
import axios from 'axios';
import { fileURLToPath } from 'url';
import { postToX } from './src/postToX.js';
import { createRealAIVideo } from './src/animateWithReplicate.js';
import { createHuggingFaceAnimation } from './src/animateWithHuggingFace.js';
import dotenv from 'dotenv';

dotenv.config();

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

async function downloadSunflowers() {
  const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Vincent_Willem_van_Gogh_127.jpg/800px-Vincent_Willem_van_Gogh_127.jpg';
  const response = await axios.get(imageUrl, { responseType: 'arraybuffer' });

  const outputDir = path.join(__dirname, 'output');
  if (!fs.existsSync(outputDir)) {
    fs.mkdirSync(outputDir, { recursive: true });
  }

  const timestamp = new Date().getTime();
  const fileName = `sunflowers_${timestamp}.jpg`;
  const filePath = path.join(outputDir, fileName);

  fs.writeFileSync(filePath, response.data);

  const metadata = {
    title: 'Sunflowers',
    artist: 'Vincent van Gogh',
    year: '1888',
    description: 'Testing different animation services',
    localPath: filePath,
    fileName: fileName,
    creditLine: 'Vincent van Gogh (Public Domain)',
  };

  return { filePath, metadata };
}

async function postWithServiceName(result, serviceName, metadata) {
  try {
    // Create custom tweet text that mentions the service
    const customTweetText = `🧪 Animation Test: ${serviceName}\n\n"${metadata.title}" by ${metadata.artist} (${metadata.year})\n\nTesting AI animation - does it move or just pan?\n\n#AIAnimation #TestPost`;

    // Post to X with custom text
    const { TwitterApi } = await import('twitter-api-v2');

    const client = new TwitterApi({
      appKey: process.env.TWITTER_API_KEY,
      appSecret: process.env.TWITTER_API_SECRET,
      accessToken: process.env.TWITTER_ACCESS_TOKEN,
      accessSecret: process.env.TWITTER_ACCESS_SECRET,
    });

    const mediaPath = result.animatedVideo || result.animatedImage || result.originalImage;

    console.log(`Uploading ${serviceName} video...`);
    const mediaId = await client.v1.uploadMedia(mediaPath);

    const tweet = await client.v2.tweet({
      text: customTweetText,
      media: {
        media_ids: [mediaId]
      }
    });

    console.log(`✅ Posted ${serviceName} test! Tweet ID: ${tweet.data.id}`);
    return tweet;

  } catch (error) {
    console.error(`Failed to post ${serviceName}:`, error.message);
    return null;
  }
}

async function testService(serviceName, animationFunc, imagePath, metadata) {
  console.log(`\n${'='.repeat(50)}`);
  console.log(`Testing: ${serviceName}`);
  console.log('='.repeat(50));

  try {
    const result = await animationFunc(imagePath, metadata);

    if (result.isAnimated || result.animatedVideo) {
      console.log(`✅ ${serviceName} created animation!`);

      // Post to X with service name in tweet
      await postWithServiceName(result, serviceName, metadata);

      return true;
    } else {
      console.log(`❌ ${serviceName} failed to create animation`);
      return false;
    }
  } catch (error) {
    console.log(`❌ ${serviceName} error:`, error.message);
    return false;
  }
}

async function runAllTests() {
  console.log('TESTING ALL ANIMATION SERVICES WITH VAN GOGH SUNFLOWERS');
  console.log('Each animation will be posted with the service name\n');

  const { filePath, metadata } = await downloadSunflowers();
  console.log('Sunflowers downloaded:', filePath);

  // Wait between posts to avoid rate limits
  const delay = ms => new Promise(resolve => setTimeout(resolve, ms));

  // Test 1: Replicate with Stable Video Diffusion
  console.log('\nStarting Replicate/SVD test...');
  await testService(
    'Replicate Stable Video Diffusion',
    createRealAIVideo,
    filePath,
    metadata
  );

  console.log('\nWaiting 10 seconds before next test...');
  await delay(10000);

  // Test 2: Hugging Face (if configured)
  if (process.env.HUGGINGFACE_TOKEN) {
    console.log('\nStarting HuggingFace test...');
    await testService(
      'HuggingFace AI Models',
      createHuggingFaceAnimation,
      filePath,
      metadata
    );
  } else {
    console.log('Skipping HuggingFace (no token configured)');
  }

  console.log('\n' + '='.repeat(50));
  console.log('ALL TESTS COMPLETE!');
  console.log('Check @goodquestionai to compare the animations');
  console.log('Reply which one has real movement vs just camera panning!');
  console.log('='.repeat(50));
}

runAllTests().catch(console.error);