Burin-Zhargal's picture
download
raw
1.91 kB
// ignore_for_file: use_build_context_synchronously
//TODO: СДЕЛАТЬ API Image2Vid+Text
// TODO: Добавить к видео текст и озвучку, эффекты
import 'dart:convert';
import 'package:advideos/screens/video_screen.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:advideos/utils/error.dart';
import 'package:http/http.dart' as http;
//Image to Video Stability AI
Future<dynamic> convertImageToVideo(
String prompt,
BuildContext context,
) async {
Uint8List imageData = Uint8List(0);
const baseUrl = 'https://api.stability.ai';
final url = Uri.parse(
'$baseUrl/v1alpha/generation/stable-diffusion-512-v2-1/text-to-image');
// Make the HTTP POST request to the Stability Platform API
final response = await http.post(
url,
headers: {
'Content-Type': 'application/json',
'Authorization':
//add ypur secreat key here
'Bearer sk-DR6RvmLPxZaU8z9DMFOg0Ecr7bfjljdssG7AerERzIrCo6FZmouH5fl',
'Accept': 'image/png',
},
body: jsonEncode({
'cfg_scale': 15,
'clip_guidance_preset': 'FAST_BLUE',
'height': 512,
'width': 512,
'samples': 1,
'steps': 150,
'seed': 0,
'style_preset': "3d-model",
'text_prompts': [
{
'text': prompt,
'weight': 1,
}
],
}),
);
if (response.statusCode == 200) {
try {
imageData = (response.bodyBytes);
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => VideoScreen(image: imageData),
));
return response.bodyBytes;
} on Exception {
return showErrorDialog('Failed to generate image', context);
}
} else {
return showErrorDialog('Failed to generate image', context);
}
}

Xet Storage Details

Size:
1.91 kB
·
Xet hash:
882723dbeebe0704fe1e5df50762eedfd702c11bdf6bd994b3b192c4087345ea

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.