Procházet zdrojové kódy

update: new yangshi

17870762608 před 2 měsíci
rodič
revize
98f977bf7a

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


+ 22 - 0
mcbridge-app/src/app/inquiry/inquiry.component.spec.ts

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

+ 69 - 0
mcbridge-app/src/app/inquiry/inquiry.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-inquiry',
+  templateUrl: './inquiry.component.html',
+  styleUrls: ['./inquiry.component.scss'],
+  standalone: true,
+  imports: [
+    IonHeader, IonToolbar, IonTitle, IonContent, 
+    IonButton,
+    IonInput,
+    IonTextarea
+  ],
+})
+export class InquiryComponent  implements OnInit {
+  userPrompt:string = ""
+  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() {}
+
+}

+ 8 - 6
mcbridge-app/src/app/tab1/tab1.page.html

@@ -16,12 +16,14 @@
   <!-- 添加搜索框 -->  
   <ion-searchbar placeholder="搜索..." (ionInput)="search($event)"></ion-searchbar>  
 
-  <div class="inquery" style="margin-top: 10px">
-    <div class="inquery-ai">
-      <ion-button color="primary" size="large" (click)="goToPage1()">
-        AI问诊
-      </ion-button>
-    </div>
+  <!-- 按钮容器 -->
+  <div class="button-container">
+    <ion-button  size="large" (click)="goToPage1()">
+      智能诊疗
+    </ion-button>
+    <ion-button  size="large" (click)="goToPage2()">
+      相似症状图查询
+    </ion-button>
   </div>
 
   <!-- 页面内容 -->  

+ 13 - 0
mcbridge-app/src/app/tab1/tab1.page.scss

@@ -21,4 +21,17 @@ ion-searchbar {
   ion-item {  
     --background: #ffffff;  
     margin: 10px 0;  
+  }
+
+  .button-container {
+    display: flex;
+    justify-content: space-between; /* 在按钮之间留出空间 */
+    margin-top: 10px; /* 可选,调整按钮的上边距 */
+  }
+  
+  .button-container ion-button {
+    flex: 1; /* 每个按钮占据相同的空间 */
+    margin: 0 5px; /* 按钮之间的间距 */
+    color: #f8f9fa;
+    background-color: #f9faf8;
   }

+ 1 - 1
mcbridge-app/src/app/tab1/tab1.page.ts

@@ -27,7 +27,7 @@ export class Tab1Page {
   }
 
   goToPage2(){
-
+    this.router.navigate(['/tabs/inquiry'])
   }
 
   currentScore: number = 0; // 初始分值

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

@@ -26,6 +26,11 @@ export const routes: Routes = [
         loadComponent: () =>
           import('../picture/picture.component').then((m) => m.PictureComponent),
       },
+      {
+        path: 'inquiry',
+        loadComponent: () =>
+          import('../inquiry/inquiry.component').then((m) => m.InquiryComponent),
+      },
       {
         path: '',
         redirectTo: '/tabs/tab1',