← back to Animate Museum Posts

test-sunflowers.js

86 lines

import { fetchRandomArtwork } from './src/fetchArtwork.js';
import { animateArtwork } from './src/animateWithGrok.js';
import { postToX } from './src/postToX.js';
import fs from 'fs';
import path from 'path';
import axios from 'axios';
import { fileURLToPath } from 'url';

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

async function testSunflowers() {
  try {
    console.log('Testing with Van Gogh Sunflowers...\n');

    // Download Sunflowers image directly
    const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/4/46/Vincent_Willem_van_Gogh_127.jpg/800px-Vincent_Willem_van_Gogh_127.jpg';

    console.log('Downloading Sunflowers painting...');
    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_test_${timestamp}.jpg`;
    const filePath = path.join(outputDir, fileName);

    fs.writeFileSync(filePath, response.data);
    console.log('Image saved:', fileName);

    const metadata = {
      title: 'Sunflowers',
      artist: 'Vincent van Gogh',
      year: '1888',
      description: 'One of Van Gogh\'s most famous paintings featuring vibrant sunflowers',
      objectNumber: 'VG-1888',
      imageUrl: imageUrl,
      localPath: filePath,
      fileName: fileName,
      museum: 'Public Domain Collection',
      creditLine: 'Vincent van Gogh (Public Domain)',
      dimensions: []
    };

    console.log('\n=== STARTING AI VIDEO GENERATION ===');
    console.log('This will use Stable Video Diffusion to create REAL animation');
    console.log('Cost: approximately $0.02\n');

    // Animate with Replicate
    const animationResult = await animateArtwork(filePath, metadata);

    if (animationResult.animatedVideo) {
      console.log('\n✅ SUCCESS! AI video created:');
      console.log('Video path:', animationResult.animatedVideo);

      const stats = fs.statSync(animationResult.animatedVideo);
      console.log('Video size:', (stats.size / 1024 / 1024).toFixed(2), 'MB');
      console.log('Format:', animationResult.videoFormat || 'mp4');

      console.log('\nPosting to X.com...');
      const tweet = await postToX(animationResult);

      console.log('\n🎉 COMPLETE!');
      console.log('Tweet posted with AI-animated video');
      console.log('Check @goodquestionai to see the animation!');

    } else {
      console.log('\n❌ Animation failed - check error messages above');
    }

  } catch (error) {
    console.error('\n❌ Test failed:', error.message);
    if (error.response) {
      console.error('API Response:', error.response.data);
    }
  }
}

console.log('='.repeat(50));
console.log('VAN GOGH SUNFLOWERS AI ANIMATION TEST');
console.log('='.repeat(50));

testSunflowers();