|
|
@@ -1,8 +1,12 @@
|
|
|
import { Component, OnInit } from '@angular/core';
|
|
|
-import { IonHeader, IonToolbar, IonTitle, IonContent, IonItem } from '@ionic/angular/standalone';
|
|
|
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonItem, IonIcon, IonButtons } from '@ionic/angular/standalone';
|
|
|
import { IonTextarea, IonButton,IonInput } from "@ionic/angular/standalone";
|
|
|
import { DalleOptions, ImagineWork, FmodeChatCompletion } from 'fmode-ng';
|
|
|
-
|
|
|
+import { Router } from '@angular/router';
|
|
|
+import {chevronBack} from 'ionicons/icons';
|
|
|
+addIcons({chevronBack})
|
|
|
+import { addIcons } from 'ionicons';
|
|
|
+import { CloudObject, CloudUser } from 'src/lib/ncloud';
|
|
|
@Component({
|
|
|
selector: 'picture',
|
|
|
templateUrl: './picture.component.html',
|
|
|
@@ -12,60 +16,10 @@ import { DalleOptions, ImagineWork, FmodeChatCompletion } from 'fmode-ng';
|
|
|
IonHeader, IonToolbar, IonTitle, IonContent,
|
|
|
IonButton,
|
|
|
IonInput,
|
|
|
- IonTextarea,IonItem
|
|
|
+ IonTextarea,IonItem,IonIcon,IonButtons
|
|
|
],
|
|
|
})
|
|
|
export class PictureComponent implements OnInit {
|
|
|
-
|
|
|
- // userPrompt:string = "犬吠水声中,桃花带露浓。\n树深时见鹿,溪午不闻钟。"
|
|
|
- // promptInput(ev:any){
|
|
|
- // this.userPrompt = ev.detail.value;
|
|
|
- // }
|
|
|
- // imagineWork:ImagineWork|undefined
|
|
|
- // images:Array<string> = []
|
|
|
- // constructor(
|
|
|
- // ){
|
|
|
- // // 示例任务,自己生成图片后请存储新的ID
|
|
|
- // this.imagineWork = new ImagineWork("");
|
|
|
- // this.imagineWork.fetchTask().then(work=>{
|
|
|
- // this.images = this.imagineWork?.images || [];
|
|
|
- // })
|
|
|
- // }
|
|
|
-
|
|
|
- // PictureDescResult:string = `` // 画面描述结果
|
|
|
- // async createImage(){
|
|
|
- // this.imagineWork = new ImagineWork();
|
|
|
- // // 文本生成
|
|
|
- // let PromptTemplate = `您是一名专业的美术画家,请您根据古诗文的内容,将其描述的画面、场景、人物、物品等用最简短的语言表达,直接写出画面,并且以中国的古风意境为主
|
|
|
- // 诗文如下:
|
|
|
- // ${this.userPrompt}
|
|
|
- // `
|
|
|
- // let completion = new FmodeChatCompletion([
|
|
|
- // {role:"system",content:""},
|
|
|
- // {role:"user",content:PromptTemplate}
|
|
|
- // ])
|
|
|
- // completion.sendCompletion().subscribe((message:any)=>{
|
|
|
- // // 打印消息体
|
|
|
- // console.log(message.content)
|
|
|
- // // 赋值消息内容给组件内属性
|
|
|
- // this.PictureDescResult = message.content
|
|
|
- // if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
|
|
|
- // // 图片生成
|
|
|
- // let PicturePrompt = `${this.PictureDescResult}\n风格:中国古风。画面不带任何文字。突出色彩。`
|
|
|
- // let options:DalleOptions = {prompt:PicturePrompt}
|
|
|
- // this.imagineWork?.draw(options).subscribe(work=>{
|
|
|
- // console.log("imagineWork",work?.toJSON())
|
|
|
- // console.log("images",work?.get("images"))
|
|
|
- // if(work?.get("images")?.length){
|
|
|
- // this.images = work?.get("images");
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // })
|
|
|
-
|
|
|
-
|
|
|
- // }
|
|
|
- // ngOnInit() {}
|
|
|
userPrompt: string = "请描述您的绘画想法"; // 用户输入的绘画想法
|
|
|
promptInput(ev: any) {
|
|
|
this.userPrompt = ev.detail.value; // 更新用户输入的绘画想法
|
|
|
@@ -74,11 +28,12 @@ export class PictureComponent implements OnInit {
|
|
|
imagineWork: ImagineWork | undefined; // 用于处理图像生成的实例
|
|
|
images: Array<string> = []; // 存储生成的图像数组
|
|
|
|
|
|
- constructor() {
|
|
|
+ constructor(private router: Router) {
|
|
|
// 初始化ImagineWork实例并获取初始任务
|
|
|
this.imagineWork = new ImagineWork("");
|
|
|
this.imagineWork.fetchTask().then(work => {
|
|
|
this.images = this.imagineWork?.images || []; // 获取已有图像
|
|
|
+ this.currentadivse = new CloudObject('padvise');
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -87,7 +42,7 @@ export class PictureComponent implements OnInit {
|
|
|
async createImage() {
|
|
|
this.imagineWork = new ImagineWork(); // 创建新的ImagineWork实例
|
|
|
// 文本生成
|
|
|
- let PromptTemplate = `您是一名专业的美术画家,请您根据用户的绘画想法,将其描述的画面、场景、人物、物品等用最简短的语言表达,直接写出画面,并且以中国的古风意境为主。
|
|
|
+ let PromptTemplate = `您是一名专业的美术画家,请您根据用户的绘画想法,将其描述的画面、场景、人物、物品等用最简短的语言表达,直接写出画面。
|
|
|
用户的绘画想法如下:
|
|
|
${this.userPrompt}
|
|
|
`;
|
|
|
@@ -107,7 +62,7 @@ export class PictureComponent implements OnInit {
|
|
|
// 判断消息是否完成
|
|
|
if (message?.complete) {
|
|
|
// 图片生成
|
|
|
- let PicturePrompt = `${this.PictureDescResult}\n风格:中国古风。画面不带任何文字。突出色彩。`;
|
|
|
+ let PicturePrompt = `${this.PictureDescResult}\n画面不带任何文字。`;
|
|
|
let options: DalleOptions = { prompt: PicturePrompt };
|
|
|
|
|
|
// 生成图像
|
|
|
@@ -118,6 +73,7 @@ export class PictureComponent implements OnInit {
|
|
|
// 更新生成的图像
|
|
|
if (work?.get("images")?.length) {
|
|
|
this.images = work?.get("images");
|
|
|
+ this.addadvise();
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -125,4 +81,28 @@ export class PictureComponent implements OnInit {
|
|
|
}
|
|
|
|
|
|
ngOnInit() {}
|
|
|
+
|
|
|
+ gopage(){
|
|
|
+ this.router.navigate(['/tabs/tab1'])
|
|
|
+ }
|
|
|
+
|
|
|
+ currentadivse: CloudObject | undefined; //
|
|
|
+ advisedata: any = {};
|
|
|
+ async addadvise() {
|
|
|
+ let currentUser = new CloudUser();
|
|
|
+ if (currentUser?.id) {
|
|
|
+ this.currentadivse?.addPointer('user', '_User', currentUser.id);
|
|
|
+ }
|
|
|
+ if(this.PictureDescResult){
|
|
|
+ this.advisedata['content']=this.PictureDescResult;
|
|
|
+ this.advisedata['type']='picture';
|
|
|
+ this.advisedata['idea']=this.userPrompt;
|
|
|
+ }
|
|
|
+ if(this.images){
|
|
|
+ this.advisedata['picture']=this.images[this.images.length-1];
|
|
|
+ }
|
|
|
+ this.currentadivse?.set(this.advisedata);
|
|
|
+ await this.currentadivse?.save();
|
|
|
+ }
|
|
|
+
|
|
|
}
|