Ver Fonte

feat: add & implement the aipicture-page page

cyx há 5 meses atrás
pai
commit
a295a7888b

+ 58 - 0
TFPower-app/src/app/page/aipicture-page/aipicture-page.component.html

@@ -0,0 +1,58 @@
+<ion-header [translucent]="true">
+  <ion-toolbar>
+    <ion-title>
+      AIpicture
+    </ion-title>
+  </ion-toolbar>
+</ion-header>
+
+<ion-content [fullscreen]="true">
+
+  <ion-card color="medium">
+    <ion-card-header>
+      <ion-card-title>AI小助手</ion-card-title>
+      <ion-card-subtitle>填写以下信息,我来给你生成图片。</ion-card-subtitle>
+    </ion-card-header>
+    <ion-list>
+      <ion-item>
+        <!-- 生成提示词 -->
+        <ion-textarea [value]="needs" (ionInput)="promptInput($event)" placeholder="DALLE3图片提示词"
+          autoGrow="true"></ion-textarea>
+      </ion-item>
+      <ion-grid [fixed]="true">
+        <ion-row style="text-align: center;">
+          <ion-button (click)="createImage()" expand="block">生成图片 {{imagineWork?.progress || 0}}</ion-button>
+        </ion-row>
+      </ion-grid>
+    </ion-list>
+  </ion-card>
+
+  <ion-card color="light">
+    <ion-card-header>
+      <ion-card-title>生成图片</ion-card-title>
+      <ion-card-subtitle>根据您填写的信息,我给你生成的图片。</ion-card-subtitle>
+    </ion-card-header>
+    <ion-list>
+      <ion-item>
+        <!-- 生成结果 -->
+        @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-item>
+    </ion-list>
+  </ion-card>
+
+
+
+</ion-content>

+ 0 - 0
TFPower-app/src/app/page/aipicture-page/aipicture-page.component.scss


+ 24 - 0
TFPower-app/src/app/page/aipicture-page/aipicture-page.component.spec.ts

@@ -0,0 +1,24 @@
+import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
+import { IonicModule } from '@ionic/angular';
+
+import { AipicturePageComponent } from './aipicture-page.component';
+
+describe('AipicturePageComponent', () => {
+  let component: AipicturePageComponent;
+  let fixture: ComponentFixture<AipicturePageComponent>;
+
+  beforeEach(waitForAsync(() => {
+    TestBed.configureTestingModule({
+      declarations: [AipicturePageComponent],
+      imports: [IonicModule.forRoot()],
+    }).compileComponents();
+
+    fixture = TestBed.createComponent(AipicturePageComponent);
+    component = fixture.componentInstance;
+    fixture.detectChanges();
+  }));
+
+  it('should create', () => {
+    expect(component).toBeTruthy();
+  });
+});

+ 95 - 0
TFPower-app/src/app/page/aipicture-page/aipicture-page.component.ts

@@ -0,0 +1,95 @@
+import { Component, OnInit } from '@angular/core';
+import { DalleOptions, ImagineWork, FmodeChatCompletion } from 'fmode-ng';
+import {
+  IonButton,
+  IonCard,
+  IonCardContent,
+  IonCardHeader,
+  IonCardSubtitle,
+  IonCardTitle,
+  IonContent,
+  IonGrid,
+  IonHeader,
+  IonItem,
+  IonList,
+  IonRow,
+  IonTextarea,
+  IonTitle,
+  IonToolbar,
+} from '@ionic/angular/standalone';
+
+@Component({
+  selector: 'app-aipicture-page',
+  templateUrl: './aipicture-page.component.html',
+  styleUrls: ['./aipicture-page.component.scss'],
+  standalone: true,
+  imports: [
+    IonHeader,
+    IonToolbar,
+    IonTitle,
+    IonContent,
+    IonTextarea,
+    IonButton,
+    IonCard,
+    IonCardContent,
+    IonCardHeader,
+    IonCardSubtitle,
+    IonCardTitle,
+    IonGrid,
+    IonList,
+    IonItem,
+    IonRow,
+  ],
+})
+export class AipicturePageComponent implements OnInit {
+  needs: string = '画一张logo, 主题是健身,要求精简大气';
+  promptInput(ev: any) {
+    this.needs = ev.detail.value;
+  }
+
+  imagineWork: ImagineWork | undefined;
+  images: Array<string> = [];
+  PictureDescResult: string = ``;
+  constructor() {
+    // 示例任务,自己生成图片后请存储新的ID
+    this.imagineWork = new ImagineWork('lpJGiFwWeA');
+    this.imagineWork.fetchTask().then((work) => {
+      this.images = this.imagineWork?.images || [];
+    });
+  }
+
+  async createImage() {
+    this.imagineWork = new ImagineWork();
+
+    // ai生成更详细的内容
+    let PromptTemplate = `请您作为一名专业的美术大家,请根据以下需求给出更详细的补充,用最少的文字表达出来。需求有:${this.needs}`;
+    console.log(PromptTemplate);
+
+    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) {
+        console.log(this.PictureDescResult);
+
+        let PicturePrompt = `${this.PictureDescResult}风格,画面不带任何文字。`;
+        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 - 0
TFPower-app/src/app/tab1/tab1.page.html

@@ -16,6 +16,9 @@
           <ion-item>
             <ion-label><a (click)="navigateTo('aiplanpage')">AIplan</a></ion-label>
           </ion-item>
+          <ion-item>
+            <ion-label><a (click)="navigateTo('aipicture')">AIpicture</a></ion-label>
+          </ion-item>
         </ion-list>
         <!-- <ion-button>Go to TodolistPage </ion-button> -->
 

+ 7 - 0
TFPower-app/src/app/tabs/tabs.routes.ts

@@ -40,6 +40,13 @@ export const routes: Routes = [
             (m) => m.AiplanPageComponent
           ),
       },
+      {
+        path: 'aipicture',
+        loadComponent: () =>
+          import('../page/aipicture-page/aipicture-page.component').then(
+            (m) => m.AipicturePageComponent
+          ),
+      },
       {
         path: '',
         redirectTo: '/tabs/tab1',