Kaynağa Gözat

fix:11-30new picture

何何何 1 yıl önce
ebeveyn
işleme
e19cbc29e5

Dosya farkı çok büyük olduğundan ihmal edildi
+ 641 - 14
paint-app/package-lock.json


+ 1 - 0
paint-app/package.json

@@ -27,6 +27,7 @@
     "@capacitor/keyboard": "6.0.3",
     "@capacitor/status-bar": "6.0.2",
     "@ionic/angular": "^8.0.0",
+    "fmode-ng": "^0.0.62",
     "ionicons": "^7.2.1",
     "rxjs": "~7.8.0",
     "tslib": "^2.3.0",

+ 23 - 0
paint-app/src/app/page-idea/page-idea.component.html

@@ -0,0 +1,23 @@
+<ion-content>
+
+  <h1>科室</h1>
+  <ion-input  [value]="keshi" (ionInput)="keshiInput($event)"></ion-input>
+
+  <!-- 文本域:生成提示词 -->
+  <h1>症状的描述</h1>
+  <ion-textarea [value]="userPrompt" (ionInput)="promptInput($event)" placeholder="文本提示词" autoGrow="true"></ion-textarea>
+  
+  <!-- 按钮:执行消息生成函数 -->
+  <ion-button (click)="sendMessage()" expand="block">初步诊断</ion-button>
+  
+  <!-- 展示:返回消息内容 -->
+  <!-- 消息传输过程中,实时预览 -->
+  @if(!isComplete){
+    <div>{{responseMsg}}</div>
+  }
+  <!-- 消息传输完成后,实时预览Markdown格式 -->
+  @if(isComplete){
+    <fm-markdown-preview class="content-style" [content]="responseMsg"></fm-markdown-preview>
+  }
+  
+</ion-content>

+ 0 - 0
paint-app/src/app/page-idea/page-idea.component.scss


+ 22 - 0
paint-app/src/app/page-idea/page-idea.component.spec.ts

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

+ 57 - 0
paint-app/src/app/page-idea/page-idea.component.ts

@@ -0,0 +1,57 @@
+import { Component, OnInit } from '@angular/core';
+import { IonHeader, IonToolbar, IonTitle, IonContent, IonButton, IonTextarea, IonInput } from '@ionic/angular/standalone';
+/** 引用:从fmode-ng库引用FmodeChatCompletion类 */
+import { FmodeChatCompletion,MarkdownPreviewModule } from 'fmode-ng';
+
+@Component({
+  selector: 'page-idea',
+  templateUrl: './page-idea.component.html',
+  styleUrls: ['./page-idea.component.scss'],
+  standalone: true,
+  imports: [IonHeader, IonToolbar, IonTitle, IonContent, IonButton,IonTextarea,IonInput,
+    // 引入fm-markdown-preview组件模块
+    MarkdownPreviewModule
+  ],
+})
+export class PageIdeaComponent  implements OnInit {
+
+  constructor() {}
+  ngOnInit(){}
+  // 用户输入提示词
+  keshi:string = "门诊"
+  keshiInput(ev:any){
+    this.keshi = ev.detail.value;
+  }
+  // 用户输入提示词
+  userPrompt:string = "请描述您的症状"
+  promptInput(ev:any){
+    this.userPrompt = ev.detail.value;
+  }
+  // 属性:组件内用于展示消息内容的变量
+  responseMsg:any = ""
+  // 方法:实例化completion对象,传入消息数组,并订阅生成的可观察对象。
+  isComplete:boolean = false; // 定义完成状态属性,用来标记是否补全完成
+  sendMessage(){
+    console.log("create")
+
+    let PromptTemplate = `
+    您作为一名专业的${this.keshi}医生,请您根据用户描述的症状,给出初步的诊断,并给出一些建议。
+    以下是用户的口述:${this.userPrompt}
+    `
+
+    let completion = new FmodeChatCompletion([
+      {role:"system",content:""},
+      {role:"user",content:PromptTemplate}
+    ])
+    completion.sendCompletion().subscribe((message:any)=>{
+      // 打印消息体
+      console.log(message.content)
+      // 赋值消息内容给组件内属性
+      this.responseMsg = message.content
+      if(message?.complete){ // 判断message为完成状态,则设置isComplete为完成
+        this.isComplete = true
+      }
+    })
+  }
+
+}

+ 33 - 0
paint-app/src/app/picture/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
paint-app/src/app/picture/picture.component.scss


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

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

+ 70 - 0
paint-app/src/app/picture/picture.component.ts

@@ -0,0 +1,70 @@
+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: 'picture',
+  templateUrl: './picture.component.html',
+  styleUrls: ['./picture.component.scss'],
+  standalone: true,
+  imports: [
+    IonHeader, IonToolbar, IonTitle, IonContent, 
+    IonButton,
+    IonInput,
+    IonTextarea
+  ],
+})
+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() {}
+
+}

+ 4 - 0
paint-app/src/app/tab1/tab1.page.html

@@ -18,6 +18,10 @@
 
 <ion-button (click)="goTestPage()">进入测试页面</ion-button>
 
+<ion-button (click)="goTestPage1()">激发灵感</ion-button>
+
+<ion-button (click)="goTestPage2()">绘画</ion-button>
+
 <h1>星星打分组件演示:分值{{currentScore}}</h1>
 <edit-rating-star
   [score]="currentScore" 

+ 7 - 1
paint-app/src/app/tab1/tab1.page.ts

@@ -19,10 +19,16 @@ export class Tab1Page {
   currentScore: number = 0; // 初始分值
 
   constructor(private router: Router){}
+
   goTestPage(){
     this.router.navigate(['/tabs/test'])
   }
-  
+  goTestPage1(){
+    this.router.navigate(['/tabs/idea'])
+  }
+  goTestPage2(){
+    this.router.navigate(['/tabs/picture'])
+  }
   handleScoreChange(newScore: number) {
     this.currentScore = newScore;
     console.log('新分值:', newScore); // 处理分值变化

+ 10 - 0
paint-app/src/app/tabs/tabs.routes.ts

@@ -26,6 +26,16 @@ export const routes: Routes = [
         loadComponent: () =>
           import('../page-test/page-test.component').then((m) => m.PageTestComponent),
       },
+      {
+        path: 'idea',
+        loadComponent: () =>
+          import('../page-idea/page-idea.component').then((m) => m.PageIdeaComponent),
+      },
+      {
+        path: 'picture',
+        loadComponent: () =>
+          import('../picture/picture.component').then((m) => m.PictureComponent),
+      },
       {
         path: '',
         redirectTo: '/tabs/tab1',

+ 21 - 0
paint-app/src/main.ts

@@ -5,10 +5,31 @@ import { IonicRouteStrategy, provideIonicAngular } from '@ionic/angular/standalo
 import { routes } from './app/app.routes';
 import { AppComponent } from './app/app.component';
 
+
+// 'r:E4KpGvTEto-159796066731732377158'
+// 引用HttpClient方法
+import { provideHttpClient } from '@angular/common/http';
+// 引用移动端授权检测供应器
+import { Diagnostic } from '@awesome-cordova-plugins/diagnostic/ngx';
+// 设置Parse服务属性
+import Parse from "parse";
+Parse.initialize("ncloudmaster");
+Parse.serverURL = "https://server.fmode.cn/parse";
+localStorage.setItem("NOVA_APIG_SERVER", 'aHR0cHMlM0ElMkYlMkZzZXJ2ZXIuZm1vZGUuY24lMkZhcGklMkZhcGlnJTJG')
+
+// 注意:替换Token 根据Token设置Parse服务帐套权限
+Parse.User.become("r:E4KpGvTEto-159796066731732377158")
+
+
+
 bootstrapApplication(AppComponent, {
   providers: [
     { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
     provideIonicAngular(),
     provideRouter(routes, withPreloading(PreloadAllModules)),
+      // 添加HttpClient供应器
+      provideHttpClient(),
+      // 添加Diagnostic
+      Diagnostic,
   ],
 });

+ 1 - 0
paint-app/tsconfig.json

@@ -2,6 +2,7 @@
 {
   "compileOnSave": false,
   "compilerOptions": {
+    "allowSyntheticDefaultImports":true,
     "baseUrl": "./",
     "outDir": "./dist/out-tsc",
     "forceConsistentCasingInFileNames": true,

Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor