-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdemo.js
More file actions
131 lines (114 loc) Β· 4.54 KB
/
demo.js
File metadata and controls
131 lines (114 loc) Β· 4.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// demo.js - ModelsLab SDK Demo
require('dotenv').config();
const {
Client,
Community,
Audio,
Video,
ImageEditing,
DeepFake,
ThreeD,
Realtime,
InteriorAPI
} = require('./dist/index');
async function runDemo() {
console.log('π ModelsLab SDK Demo Starting...\n');
// Initialize client
const apiKey = process.env.API_KEY;
if (!apiKey) {
console.error('β API_KEY not found in environment variables');
console.log('Please set your API key in the .env file');
return;
}
// Initialize API clients
const community = new Community(apiKey);
const audio = new Audio(apiKey);
const video = new Video(apiKey);
const imageEditing = new ImageEditing(apiKey);
const deepfake = new DeepFake(apiKey);
const threeD = new ThreeD(apiKey);
const realtime = new Realtime(apiKey);
const interior = new InteriorAPI(apiKey);
console.log('π― Available API Endpoints:');
console.log('πΈ Community API - Text to Image, Image to Image, Inpainting, ControlNet');
console.log('π΅ Audio API - Text to Speech, Voice Cloning, Music Generation');
console.log('π¬ Video API - Text to Video, Image to Video');
console.log('β¨ Image Editing API - Background Removal, Super Resolution, Fashion');
console.log('π DeepFake API - Face Swap, Video Swap');
console.log('ποΈ 3D API - Text to 3D, Image to 3D');
console.log('β‘ Realtime API - Fast Image Generation');
console.log('π Interior API - Interior Design, Room Decoration\n');
// Example 1: Text to Image Generation
console.log('π¨ Example 1: Text to Image Generation');
try {
const textToImageRequest = {
key: apiKey,
model_id: "flux",
prompt: "A beautiful sunset over mountains, digital art style",
width: 512,
height: 512,
samples: 1,
num_inference_steps: 20,
guidance_scale: 7.5,
safety_checker: "yes",
enhance_prompt: "yes"
};
console.log('π€ Sending text-to-image request...');
const result = await community.textToImage(textToImageRequest);
console.log('π₯ Response received:', JSON.stringify(result, null, 2));
if (result.id) {
console.log('π Fetching result...');
const fetchResult = await community.fetch(result.id);
console.log('β
Final result:', JSON.stringify(fetchResult, null, 2));
}
} catch (error) {
console.error('β Text to Image Error:', error.message);
}
console.log('\n' + '='.repeat(50) + '\n');
// Example 2: Text to Speech
console.log('π£οΈ Example 2: Text to Speech');
try {
const textToSpeechRequest = {
key: apiKey,
prompt: "Hello, this is a test of the ModelsLab text to speech API!",
voice_id: "madison",
language: "american english"
};
console.log('π€ Sending text-to-speech request...');
const result = await audio.textToSpeech(textToSpeechRequest);
console.log('π₯ Response received:', JSON.stringify(result, null, 2));
if (result.id) {
console.log('π Fetching result...');
const fetchResult = await audio.fetch(result.id);
console.log('β
Final result:', JSON.stringify(fetchResult, null, 2));
}
} catch (error) {
console.error('β Text to Speech Error:', error.message);
}
console.log('\n' + '='.repeat(50) + '\n');
// Example 3: Background Removal
console.log('πΌοΈ Example 3: Background Removal');
try {
const backgroundRemovalRequest = {
key: apiKey,
init_image: "https://example.com/sample-image.jpg" // You would use a real image URL here
};
console.log('π€ Sending background removal request...');
console.log('βΉοΈ Note: This would require a valid image URL');
// Uncomment the next lines to actually make the request
// const result = await imageEditing.backgroundRemover(backgroundRemovalRequest);
// console.log('π₯ Response received:', JSON.stringify(result, null, 2));
console.log('βοΈ Skipping actual request (no valid image URL provided)');
} catch (error) {
console.error('β Background Removal Error:', error.message);
}
console.log('\nπ Demo completed! Check the ModelsLab documentation for more examples:');
console.log('π https://docs.modelslab.com');
console.log('\nπ‘ Tips:');
console.log('- Replace image URLs with actual images for image-based APIs');
console.log('- Check API response for task IDs and use fetch() to get results');
console.log('- Adjust parameters based on your specific use case');
console.log('- Monitor your API usage and credits at https://modelslab.com/dashboard');
}
// Run the demo
runDemo().catch(console.error);