ソースを参照

增加了生成图片

yuebuzu-creater 5 ヶ月 前
コミット
9998d7a1a2

+ 2 - 1
wisdom-app/src/app/page-inquiry/page-inquiry.component.ts

@@ -16,6 +16,7 @@ import { FmodeChatCompletion,MarkdownPreviewModule } from 'fmode-ng';
 export class PageInquiryComponent  implements OnInit {
   constructor() {}
   ngOnInit(){}
+  
   // 用户输入提示词
   keshi:string = "门诊"
   keshiInput(ev:any){
@@ -47,7 +48,7 @@ export class PageInquiryComponent  implements OnInit {
       console.log(message.content)
       // 赋值消息内容给组件内属性
       this.responseMsg = message.content
-      if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
+      if(message.complete){ // 判断message为完成状态,则设置isComplete为完成
         this.isComplete = true
       }
     })

+ 33 - 0
wisdom-app/src/app/poem-picture/poem-picture.component.html

@@ -0,0 +1,33 @@
+<ion-header [translucent]="true">
+  <ion-toolbar>
+    <ion-title>
+      示例:古诗文意境生成{{imagineWork?.progress || 0}}
+    </ion-title> 
+  </ion-toolbar>
+</ion-header>
+
+<ion-content [fullscreen]="true">
+  <!-- 生成提示词 -->
+  <ion-textarea [value]="userPrompt" (ionInput)="promptInput($event)" placeholder="古诗文填写" autoGrow="true"></ion-textarea>
+  <ion-button (click)="createImage()" expand="block">生成意境</ion-button>
+  <!-- 意境画面提示词 -->
+  <div>
+    {{PictureDescResult}}
+  </div>
+  <!-- 生成结果 -->
+  @if(images.length) {
+    @for(imageUrl of images;track imageUrl){
+      <img [src]="imageUrl" alt="" srcset="">
+    }
+  }
+  <!-- 生成状态 -->
+  @if(!images.length){
+    @if(imagineWork){
+      <h1>生成中</h1>
+    }
+    @if(!imagineWork){
+      <h1>未开始</h1>
+    }
+  }
+
+</ion-content>

+ 0 - 0
wisdom-app/src/app/poem-picture/poem-picture.component.scss


+ 22 - 0
wisdom-app/src/app/poem-picture/poem-picture.component.spec.ts

@@ -0,0 +1,22 @@
+import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+
+import { PoemPictureComponent } from './poem-picture.component';
+
+describe('PoemPictureComponent', () => {
+  let component: PoemPictureComponent;
+  let fixture: ComponentFixture<PoemPictureComponent>;
+
+  beforeEach(waitForAsync(() => {
+    TestBed.configureTestingModule({
+      imports: [PoemPictureComponent],
+    }).compileComponents();
+
+    fixture = TestBed.createComponent(PoemPictureComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  }));
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 69 - 0
wisdom-app/src/app/poem-picture/poem-picture.component.ts

@@ -0,0 +1,69 @@
+import { Component, OnInit } from '@angular/core';
+import { IonHeader, IonToolbar, IonTitle, IonContent } from '@ionic/angular/standalone';
+import { IonTextarea, IonButton,IonInput } from "@ionic/angular/standalone";
+import { DalleOptions, ImagineWork, FmodeChatCompletion } from 'fmode-ng';
+
+@Component({
+  selector: 'app-poem-picture',
+  templateUrl: './poem-picture.component.html',
+  styleUrls: ['./poem-picture.component.scss'],
+  standalone: true,
+  imports: [
+    IonHeader, IonToolbar, IonTitle, IonContent, 
+    IonButton,
+    IonInput,
+    IonTextarea
+  ],
+})
+export class PoemPictureComponent  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("4mPR0IW1i5");
+    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() {}
+
+}

+ 3 - 1
wisdom-app/src/app/tab1/tab1.page.html

@@ -23,6 +23,8 @@
       </ion-button>
     </div>
   </div>
-
+  <ion-button expand="block" color="primary" size="large" (click)="goToPicture()">
+    生成图片
+  </ion-button>
   <app-explore-container name="智养"></app-explore-container>
 </ion-content>

+ 5 - 1
wisdom-app/src/app/tab1/tab1.page.ts

@@ -37,6 +37,9 @@ export class Tab1Page {
     this.router.navigate(['/tabs/page-test'])
   }
 
+  goToPicture(){
+    this.router.navigate(['/tabs/picture'])
+  }
   searchContent:string = ''; //搜索内容
 
   handleInput(ev:any) {
@@ -52,7 +55,8 @@ export class Tab1Page {
       console.log("搜索内容: ",this.searchContent)
       this.searchContent = '';
     }
-
   }
+
+
   ngOnInit() {}
 }

+ 5 - 0
wisdom-app/src/app/tabs/tabs.routes.ts

@@ -26,6 +26,11 @@ export const routes: Routes = [
         loadComponent: () =>
           import('../tab4/tab4.page').then((m) => m.Tab4Page),
       },
+      {
+        path: 'picture',
+        loadComponent: () =>
+          import('../poem-picture/poem-picture.component').then((m) => m.PoemPictureComponent),
+      },
       {
         path: 'inquiry',
         loadComponent: () =>

+ 1 - 1
wisdom-app/src/main.ts

@@ -17,7 +17,7 @@ Parse.serverURL = "https://server.fmode.cn/parse";
 localStorage.setItem("NOVA_APIG_SERVER", 'aHR0cHMlM0ElMkYlMkZzZXJ2ZXIuZm1vZGUuY24lMkZhcGklMkZhcGlnJTJG')
 
 // 注意:替换Token 根据Token设置Parse服务帐套权限
-Parse.User.become('r:6841da061563b22339ea0799f94c3475')
+Parse.User.become('r:ef31d9ab3a3eef080f4a0920a8e463e6')
 
 bootstrapApplication(AppComponent, {
   providers: [

+ 1 - 0
wisdom-app/src/web3-1021

@@ -0,0 +1 @@
+Subproject commit e4646ef9439e4aa47bd19ad628d311f640d764b0