mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: remove stability ai (#5927)
* chore: remove stability ai * chore: remove stabilityAI widgets --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
parent
14b60fb9b0
commit
a29b170b13
@ -102,7 +102,6 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
UploadImageType.local,
|
UploadImageType.local,
|
||||||
UploadImageType.url,
|
UploadImageType.url,
|
||||||
UploadImageType.unsplash,
|
UploadImageType.unsplash,
|
||||||
UploadImageType.stabilityAI,
|
|
||||||
],
|
],
|
||||||
onSelectedLocalImages: (paths) {
|
onSelectedLocalImages: (paths) {
|
||||||
controller.close();
|
controller.close();
|
||||||
@ -188,12 +187,13 @@ class ImagePlaceholderState extends State<ImagePlaceholder> {
|
|||||||
return [
|
return [
|
||||||
Flexible(
|
Flexible(
|
||||||
child: FlowyText(
|
child: FlowyText(
|
||||||
PlatformExtension.isDesktop
|
PlatformExtension.isDesktop
|
||||||
? isDraggingFiles
|
? isDraggingFiles
|
||||||
? LocaleKeys.document_plugins_image_dropImageToInsert.tr()
|
? LocaleKeys.document_plugins_image_dropImageToInsert.tr()
|
||||||
: LocaleKeys.document_plugins_image_addAnImageDesktop.tr()
|
: LocaleKeys.document_plugins_image_addAnImageDesktop.tr()
|
||||||
: LocaleKeys.document_plugins_image_addAnImageMobile.tr(),
|
: LocaleKeys.document_plugins_image_addAnImageMobile.tr(),
|
||||||
color: Theme.of(context).hintColor,),
|
color: Theme.of(context).hintColor,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
|
|
||||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
||||||
@ -25,6 +22,8 @@ import 'package:flowy_infra/size.dart';
|
|||||||
import 'package:flowy_infra/theme_extension.dart';
|
import 'package:flowy_infra/theme_extension.dart';
|
||||||
import 'package:flowy_infra/uuid.dart';
|
import 'package:flowy_infra/uuid.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
@ -129,7 +128,7 @@ class _MultiImageMenuState extends State<MultiImageMenu> {
|
|||||||
UploadImageType.local,
|
UploadImageType.local,
|
||||||
UploadImageType.url,
|
UploadImageType.url,
|
||||||
UploadImageType.unsplash,
|
UploadImageType.unsplash,
|
||||||
UploadImageType.stabilityAI,
|
|
||||||
],
|
],
|
||||||
onSelectedLocalImages: insertLocalImages,
|
onSelectedLocalImages: insertLocalImages,
|
||||||
onSelectedAIImage: insertAIImage,
|
onSelectedAIImage: insertAIImage,
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
||||||
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
import 'package:appflowy/generated/flowy_svgs.g.dart';
|
||||||
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';
|
import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';
|
||||||
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
import 'package:appflowy/plugins/document/application/document_bloc.dart';
|
||||||
import 'package:appflowy/plugins/document/application/document_service.dart';
|
import 'package:appflowy/plugins/document/application/document_service.dart';
|
||||||
@ -24,6 +22,7 @@ import 'package:easy_localization/easy_localization.dart';
|
|||||||
import 'package:flowy_infra/uuid.dart';
|
import 'package:flowy_infra/uuid.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/hover.dart';
|
import 'package:flowy_infra_ui/style_widget/hover.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
@ -67,19 +66,22 @@ class MultiImagePlaceholderState extends State<MultiImagePlaceholder> {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 12),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
FlowySvg(FlowySvgs.slash_menu_icon_photo_gallery_s,
|
FlowySvg(
|
||||||
color: Theme.of(context).hintColor,
|
FlowySvgs.slash_menu_icon_photo_gallery_s,
|
||||||
size: const Size.square(24),),
|
color: Theme.of(context).hintColor,
|
||||||
|
size: const Size.square(24),
|
||||||
|
),
|
||||||
const HSpace(10),
|
const HSpace(10),
|
||||||
FlowyText(
|
FlowyText(
|
||||||
PlatformExtension.isDesktop
|
PlatformExtension.isDesktop
|
||||||
? isDraggingFiles
|
? isDraggingFiles
|
||||||
? LocaleKeys.document_plugins_image_dropImageToInsert
|
? LocaleKeys.document_plugins_image_dropImageToInsert
|
||||||
.tr()
|
.tr()
|
||||||
: LocaleKeys.document_plugins_image_addAnImageDesktop
|
: LocaleKeys.document_plugins_image_addAnImageDesktop
|
||||||
.tr()
|
.tr()
|
||||||
: LocaleKeys.document_plugins_image_addAnImageMobile.tr(),
|
: LocaleKeys.document_plugins_image_addAnImageMobile.tr(),
|
||||||
color: Theme.of(context).hintColor,),
|
color: Theme.of(context).hintColor,
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -104,7 +106,6 @@ class MultiImagePlaceholderState extends State<MultiImagePlaceholder> {
|
|||||||
UploadImageType.local,
|
UploadImageType.local,
|
||||||
UploadImageType.url,
|
UploadImageType.url,
|
||||||
UploadImageType.unsplash,
|
UploadImageType.unsplash,
|
||||||
UploadImageType.stabilityAI,
|
|
||||||
],
|
],
|
||||||
onSelectedLocalImages: (paths) {
|
onSelectedLocalImages: (paths) {
|
||||||
controller.close();
|
controller.close();
|
||||||
|
@ -1,17 +1,15 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cover_editor.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/cover_editor.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/unsplash_image_widget.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/unsplash_image_widget.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/stability_ai_image_widget.dart';
|
//import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/stability_ai_image_widget.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/upload_image_menu/widgets/upload_image_file_widget.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
||||||
import 'package:appflowy/user/application/user_service.dart';
|
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart' hide ColorOption;
|
import 'package:appflowy_editor/appflowy_editor.dart' hide ColorOption;
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
import 'package:flowy_infra/theme_extension.dart';
|
import 'package:flowy_infra/theme_extension.dart';
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
||||||
import 'package:flowy_infra_ui/style_widget/hover.dart';
|
import 'package:flowy_infra_ui/style_widget/hover.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'widgets/embed_image_url_widget.dart';
|
import 'widgets/embed_image_url_widget.dart';
|
||||||
|
|
||||||
@ -19,8 +17,6 @@ enum UploadImageType {
|
|||||||
local,
|
local,
|
||||||
url,
|
url,
|
||||||
unsplash,
|
unsplash,
|
||||||
stabilityAI,
|
|
||||||
// openAI,
|
|
||||||
color;
|
color;
|
||||||
|
|
||||||
String get description {
|
String get description {
|
||||||
@ -31,10 +27,6 @@ enum UploadImageType {
|
|||||||
return LocaleKeys.document_imageBlock_embedLink_label.tr();
|
return LocaleKeys.document_imageBlock_embedLink_label.tr();
|
||||||
case UploadImageType.unsplash:
|
case UploadImageType.unsplash:
|
||||||
return LocaleKeys.document_imageBlock_unsplash_label.tr();
|
return LocaleKeys.document_imageBlock_unsplash_label.tr();
|
||||||
// case UploadImageType.openAI:
|
|
||||||
// return LocaleKeys.document_imageBlock_ai_label.tr();
|
|
||||||
case UploadImageType.stabilityAI:
|
|
||||||
return LocaleKeys.document_imageBlock_stability_ai_label.tr();
|
|
||||||
case UploadImageType.color:
|
case UploadImageType.color:
|
||||||
return LocaleKeys.document_plugins_cover_colors.tr();
|
return LocaleKeys.document_plugins_cover_colors.tr();
|
||||||
}
|
}
|
||||||
@ -68,33 +60,12 @@ class UploadImageMenu extends StatefulWidget {
|
|||||||
class _UploadImageMenuState extends State<UploadImageMenu> {
|
class _UploadImageMenuState extends State<UploadImageMenu> {
|
||||||
late final List<UploadImageType> values;
|
late final List<UploadImageType> values;
|
||||||
int currentTabIndex = 0;
|
int currentTabIndex = 0;
|
||||||
bool supportOpenAI = false;
|
|
||||||
bool supportStabilityAI = false;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
|
|
||||||
values = widget.supportTypes;
|
values = widget.supportTypes;
|
||||||
UserBackendService.getCurrentUserProfile().then(
|
|
||||||
(value) {
|
|
||||||
final supportOpenAI = value.fold(
|
|
||||||
(s) => s.openaiKey.isNotEmpty,
|
|
||||||
(e) => false,
|
|
||||||
);
|
|
||||||
final supportStabilityAI = value.fold(
|
|
||||||
(s) => s.stabilityAiKey.isNotEmpty,
|
|
||||||
(e) => false,
|
|
||||||
);
|
|
||||||
if (supportOpenAI != this.supportOpenAI ||
|
|
||||||
supportStabilityAI != this.supportStabilityAI) {
|
|
||||||
setState(() {
|
|
||||||
this.supportOpenAI = supportOpenAI;
|
|
||||||
this.supportStabilityAI = supportStabilityAI;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -196,23 +167,6 @@ class _UploadImageMenuState extends State<UploadImageMenu> {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
case UploadImageType.stabilityAI:
|
|
||||||
return supportStabilityAI
|
|
||||||
? Expanded(
|
|
||||||
child: Container(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: StabilityAIImageWidget(
|
|
||||||
onSelectImage: (url) => widget.onSelectedLocalImages([url]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Padding(
|
|
||||||
padding: const EdgeInsets.all(8.0),
|
|
||||||
child: FlowyText(
|
|
||||||
LocaleKeys.document_imageBlock_pleaseInputYourStabilityAIKey
|
|
||||||
.tr(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
case UploadImageType.color:
|
case UploadImageType.color:
|
||||||
final theme = Theme.of(context);
|
final theme = Theme.of(context);
|
||||||
final padding = PlatformExtension.isMobile
|
final padding = PlatformExtension.isMobile
|
||||||
|
@ -1,105 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
|
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/ai_client.dart';
|
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/error.dart';
|
|
||||||
import 'package:appflowy/startup/startup.dart';
|
|
||||||
import 'package:appflowy_result/appflowy_result.dart';
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
||||||
|
|
||||||
class OpenAIImageWidget extends StatefulWidget {
|
|
||||||
const OpenAIImageWidget({
|
|
||||||
super.key,
|
|
||||||
required this.onSelectNetworkImage,
|
|
||||||
});
|
|
||||||
|
|
||||||
final void Function(String url) onSelectNetworkImage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<OpenAIImageWidget> createState() => _OpenAIImageWidgetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _OpenAIImageWidgetState extends State<OpenAIImageWidget> {
|
|
||||||
Future<FlowyResult<List<String>, AIError>>? future;
|
|
||||||
String query = '';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: FlowyTextField(
|
|
||||||
hintText: LocaleKeys.document_imageBlock_ai_placeholder.tr(),
|
|
||||||
onChanged: (value) => query = value,
|
|
||||||
onEditingComplete: _search,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const HSpace(4.0),
|
|
||||||
FlowyButton(
|
|
||||||
useIntrinsicWidth: true,
|
|
||||||
text: FlowyText(
|
|
||||||
LocaleKeys.search_label.tr(),
|
|
||||||
),
|
|
||||||
onTap: _search,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const VSpace(12.0),
|
|
||||||
if (future != null)
|
|
||||||
Expanded(
|
|
||||||
child: FutureBuilder(
|
|
||||||
future: future,
|
|
||||||
builder: (context, value) {
|
|
||||||
final data = value.data;
|
|
||||||
if (!value.hasData ||
|
|
||||||
value.connectionState != ConnectionState.done ||
|
|
||||||
data == null) {
|
|
||||||
return const CircularProgressIndicator.adaptive();
|
|
||||||
}
|
|
||||||
return data.fold(
|
|
||||||
(s) => GridView.count(
|
|
||||||
crossAxisCount: 3,
|
|
||||||
mainAxisSpacing: 16.0,
|
|
||||||
crossAxisSpacing: 10.0,
|
|
||||||
childAspectRatio: 4 / 3,
|
|
||||||
children: s
|
|
||||||
.map(
|
|
||||||
(e) => GestureDetector(
|
|
||||||
onTap: () => widget.onSelectNetworkImage(e),
|
|
||||||
child: Image.network(e),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.toList(),
|
|
||||||
),
|
|
||||||
(e) => Center(
|
|
||||||
child: FlowyText(
|
|
||||||
e.message,
|
|
||||||
maxLines: 3,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _search() async {
|
|
||||||
final openAI = await getIt.getAsync<AIRepository>();
|
|
||||||
setState(() {
|
|
||||||
future = openAI.generateImage(
|
|
||||||
prompt: query,
|
|
||||||
n: 6,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,120 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
import 'dart:io';
|
|
||||||
|
|
||||||
import 'package:appflowy/generated/locale_keys.g.dart';
|
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_client.dart';
|
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_error.dart';
|
|
||||||
import 'package:appflowy/startup/startup.dart';
|
|
||||||
import 'package:appflowy_result/appflowy_result.dart';
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
|
||||||
import 'package:flowy_infra/uuid.dart';
|
|
||||||
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:path/path.dart' as p;
|
|
||||||
import 'package:path_provider/path_provider.dart';
|
|
||||||
|
|
||||||
class StabilityAIImageWidget extends StatefulWidget {
|
|
||||||
const StabilityAIImageWidget({
|
|
||||||
super.key,
|
|
||||||
required this.onSelectImage,
|
|
||||||
});
|
|
||||||
|
|
||||||
final void Function(String url) onSelectImage;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<StabilityAIImageWidget> createState() => _StabilityAIImageWidgetState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _StabilityAIImageWidgetState extends State<StabilityAIImageWidget> {
|
|
||||||
Future<FlowyResult<List<String>, StabilityAIRequestError>>? future;
|
|
||||||
String query = '';
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Column(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Row(
|
|
||||||
mainAxisSize: MainAxisSize.min,
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: FlowyTextField(
|
|
||||||
hintText: LocaleKeys
|
|
||||||
.document_imageBlock_stability_ai_placeholder
|
|
||||||
.tr(),
|
|
||||||
onChanged: (value) => query = value,
|
|
||||||
onEditingComplete: _search,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const HSpace(4.0),
|
|
||||||
FlowyButton(
|
|
||||||
useIntrinsicWidth: true,
|
|
||||||
text: FlowyText(
|
|
||||||
LocaleKeys.search_label.tr(),
|
|
||||||
),
|
|
||||||
onTap: _search,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
const VSpace(12.0),
|
|
||||||
if (future != null)
|
|
||||||
Expanded(
|
|
||||||
child: FutureBuilder(
|
|
||||||
future: future,
|
|
||||||
builder: (context, value) {
|
|
||||||
final data = value.data;
|
|
||||||
if (!value.hasData ||
|
|
||||||
value.connectionState != ConnectionState.done ||
|
|
||||||
data == null) {
|
|
||||||
return const CircularProgressIndicator.adaptive();
|
|
||||||
}
|
|
||||||
return data.fold(
|
|
||||||
(s) => GridView.count(
|
|
||||||
crossAxisCount: 3,
|
|
||||||
mainAxisSpacing: 16.0,
|
|
||||||
crossAxisSpacing: 10.0,
|
|
||||||
childAspectRatio: 4 / 3,
|
|
||||||
children: s.map(
|
|
||||||
(e) {
|
|
||||||
final base64Image = base64Decode(e);
|
|
||||||
return GestureDetector(
|
|
||||||
onTap: () async {
|
|
||||||
final tempDirectory = await getTemporaryDirectory();
|
|
||||||
final path = p.join(
|
|
||||||
tempDirectory.path,
|
|
||||||
'${uuid()}.png',
|
|
||||||
);
|
|
||||||
File(path).writeAsBytesSync(base64Image);
|
|
||||||
widget.onSelectImage(path);
|
|
||||||
},
|
|
||||||
child: Image.memory(base64Image),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
).toList(),
|
|
||||||
),
|
|
||||||
(e) => Center(
|
|
||||||
child: FlowyText(
|
|
||||||
e.message,
|
|
||||||
maxLines: 3,
|
|
||||||
textAlign: TextAlign.center,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void _search() async {
|
|
||||||
final stabilityAI = await getIt.getAsync<StabilityAIRepository>();
|
|
||||||
setState(() {
|
|
||||||
future = stabilityAI.generateImage(
|
|
||||||
prompt: query,
|
|
||||||
n: 6,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'dart:convert';
|
|
||||||
|
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_error.dart';
|
|
||||||
import 'package:appflowy_result/appflowy_result.dart';
|
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
|
|
||||||
enum StabilityAIRequestType {
|
|
||||||
imageGenerations;
|
|
||||||
|
|
||||||
Uri get uri {
|
|
||||||
switch (this) {
|
|
||||||
case StabilityAIRequestType.imageGenerations:
|
|
||||||
return Uri.parse(
|
|
||||||
'https://api.stability.ai/v1/generation/stable-diffusion-xl-1024-v1-0/text-to-image',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class StabilityAIRepository {
|
|
||||||
/// Generate image from Stability AI
|
|
||||||
///
|
|
||||||
/// [prompt] is the prompt text
|
|
||||||
/// [n] is the number of images to generate
|
|
||||||
///
|
|
||||||
/// the return value is a list of base64 encoded images
|
|
||||||
Future<FlowyResult<List<String>, StabilityAIRequestError>> generateImage({
|
|
||||||
required String prompt,
|
|
||||||
int n = 1,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
class HttpStabilityAIRepository implements StabilityAIRepository {
|
|
||||||
const HttpStabilityAIRepository({
|
|
||||||
required this.client,
|
|
||||||
required this.apiKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
final http.Client client;
|
|
||||||
final String apiKey;
|
|
||||||
|
|
||||||
Map<String, String> get headers => {
|
|
||||||
'Authorization': 'Bearer $apiKey',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
};
|
|
||||||
|
|
||||||
@override
|
|
||||||
Future<FlowyResult<List<String>, StabilityAIRequestError>> generateImage({
|
|
||||||
required String prompt,
|
|
||||||
int n = 1,
|
|
||||||
}) async {
|
|
||||||
final parameters = {
|
|
||||||
'text_prompts': [
|
|
||||||
{
|
|
||||||
'text': prompt,
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'samples': n,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
final response = await client.post(
|
|
||||||
StabilityAIRequestType.imageGenerations.uri,
|
|
||||||
headers: headers,
|
|
||||||
body: json.encode(parameters),
|
|
||||||
);
|
|
||||||
|
|
||||||
final data = json.decode(
|
|
||||||
utf8.decode(response.bodyBytes),
|
|
||||||
);
|
|
||||||
if (response.statusCode == 200) {
|
|
||||||
final artifacts = data['artifacts'] as List;
|
|
||||||
final base64Images = artifacts
|
|
||||||
.map(
|
|
||||||
(e) => e['base64'].toString(),
|
|
||||||
)
|
|
||||||
.toList();
|
|
||||||
return FlowyResult.success(base64Images);
|
|
||||||
} else {
|
|
||||||
return FlowyResult.failure(
|
|
||||||
StabilityAIRequestError(
|
|
||||||
data['message'].toString(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return FlowyResult.failure(
|
|
||||||
StabilityAIRequestError(
|
|
||||||
error.toString(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
class StabilityAIRequestError {
|
|
||||||
StabilityAIRequestError(this.message);
|
|
||||||
|
|
||||||
final String message;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String toString() {
|
|
||||||
return 'StabilityAIRequestError{message: $message}';
|
|
||||||
}
|
|
||||||
}
|
|
@ -4,7 +4,6 @@ import 'package:appflowy/env/cloud_env.dart';
|
|||||||
import 'package:appflowy/plugins/document/application/prelude.dart';
|
import 'package:appflowy/plugins/document/application/prelude.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/ai_client.dart';
|
import 'package:appflowy/plugins/document/presentation/editor_plugins/openai/service/ai_client.dart';
|
||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/stability_ai/stability_ai_client.dart';
|
|
||||||
import 'package:appflowy/plugins/trash/application/prelude.dart';
|
import 'package:appflowy/plugins/trash/application/prelude.dart';
|
||||||
import 'package:appflowy/shared/appflowy_cache_manager.dart';
|
import 'package:appflowy/shared/appflowy_cache_manager.dart';
|
||||||
import 'package:appflowy/shared/custom_image_cache_manager.dart';
|
import 'package:appflowy/shared/custom_image_cache_manager.dart';
|
||||||
@ -43,7 +42,6 @@ import 'package:flowy_infra/file_picker/file_picker_impl.dart';
|
|||||||
import 'package:flowy_infra/file_picker/file_picker_service.dart';
|
import 'package:flowy_infra/file_picker/file_picker_service.dart';
|
||||||
import 'package:fluttertoast/fluttertoast.dart';
|
import 'package:fluttertoast/fluttertoast.dart';
|
||||||
import 'package:get_it/get_it.dart';
|
import 'package:get_it/get_it.dart';
|
||||||
import 'package:http/http.dart' as http;
|
|
||||||
|
|
||||||
class DependencyResolver {
|
class DependencyResolver {
|
||||||
static Future<void> resolve(
|
static Future<void> resolve(
|
||||||
@ -100,23 +98,6 @@ void _resolveCommonService(
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
getIt.registerFactoryAsync<StabilityAIRepository>(
|
|
||||||
() async {
|
|
||||||
final result = await UserBackendService.getCurrentUserProfile();
|
|
||||||
return result.fold(
|
|
||||||
(s) {
|
|
||||||
return HttpStabilityAIRepository(
|
|
||||||
client: http.Client(),
|
|
||||||
apiKey: s.stabilityAiKey,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
(e) {
|
|
||||||
throw Exception('Failed to get user profile: ${e.msg}');
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
getIt.registerFactory<ClipboardService>(
|
getIt.registerFactory<ClipboardService>(
|
||||||
() => ClipboardService(),
|
() => ClipboardService(),
|
||||||
);
|
);
|
||||||
|
@ -1159,7 +1159,6 @@
|
|||||||
"tooltipSelectIcon": "Select icon",
|
"tooltipSelectIcon": "Select icon",
|
||||||
"selectAnIcon": "Select an icon",
|
"selectAnIcon": "Select an icon",
|
||||||
"pleaseInputYourOpenAIKey": "please input your AI key",
|
"pleaseInputYourOpenAIKey": "please input your AI key",
|
||||||
"pleaseInputYourStabilityAIKey": "please input your Stability AI key",
|
|
||||||
"clickToLogout": "Click to logout the current user"
|
"clickToLogout": "Click to logout the current user"
|
||||||
},
|
},
|
||||||
"mobile": {
|
"mobile": {
|
||||||
@ -1713,7 +1712,6 @@
|
|||||||
},
|
},
|
||||||
"searchForAnImage": "Search for an image",
|
"searchForAnImage": "Search for an image",
|
||||||
"pleaseInputYourOpenAIKey": "please input your AI key in Settings page",
|
"pleaseInputYourOpenAIKey": "please input your AI key in Settings page",
|
||||||
"pleaseInputYourStabilityAIKey": "please input your Stability AI key in Settings page",
|
|
||||||
"saveImageToGallery": "Save image",
|
"saveImageToGallery": "Save image",
|
||||||
"failedToAddImageToGallery": "Failed to add image to gallery",
|
"failedToAddImageToGallery": "Failed to add image to gallery",
|
||||||
"successToAddImageToGallery": "Image added to gallery successfully",
|
"successToAddImageToGallery": "Image added to gallery successfully",
|
||||||
@ -2411,4 +2409,4 @@
|
|||||||
"commentAddedSuccessfully": "Comment added successfully.",
|
"commentAddedSuccessfully": "Comment added successfully.",
|
||||||
"commentAddedSuccessTip": "You've just added or replied to a comment. Would you like to jump to the top to see the latest comments?"
|
"commentAddedSuccessTip": "You've just added or replied to a comment. Would you like to jump to the top to see the latest comments?"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user