Commit e5ef6b8b authored by salukbawa's avatar salukbawa

create take image module

parent 08bf7b02
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SkinDiseaseTakeImagePage } from './skin-disease-take-image.page';
const routes: Routes = [
{
path: '',
component: SkinDiseaseTakeImagePage
}
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class SkinDiseaseTakeImagePageRoutingModule {}
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { SkinDiseaseTakeImagePageRoutingModule } from './skin-disease-take-image-routing.module';
import { SkinDiseaseTakeImagePage } from './skin-disease-take-image.page';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
SkinDiseaseTakeImagePageRoutingModule,
ReactiveFormsModule
],
declarations: [SkinDiseaseTakeImagePage]
})
export class SkinDiseaseTakeImagePageModule {}
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button></ion-back-button>
</ion-buttons>
</ion-toolbar>
</ion-header>
<ion-content>
<div class="container-fluid" style="background-color: #E9F0FB">
<div class="row ion-justify-content-center ion-align-items-center" style="height: 100vh">
<div class="col-11">
<div class="row ion-justify-content-center">
<div class="col-5">
<img src="assets/img.png">
</div>
</div>
<div class="row">
<div class="col">
<h1 class="ion-text-center fw-bolder">BEST BARK</h1>
<h3 class="ion-text-center">Skin disease detection</h3>
<h5 class="ion-text-center text-success" *ngIf="prediction">Detected disease: {{prediction['pred']}}</h5>
</div>
</div>
<form [formGroup] = "uploadForm" (ngSubmit)="onSubmit()">
<img id="blah" [src]="imageSrc || 'http://placehold.it/180'" alt="your image" style="width: 100%" *ngIf="imageSrc" class="ion-text-center"/>
<div class="d-grid gap-2" *ngIf="!imageSrc">
<label for="formFile" class="btn btn-lg btn-secondary" type="button" style="background-color: #5b628f">Take a photo / Select image</label>
<input class="btn btn-lg btn-secondary" type="file" id="formFile" style="visibility:hidden;" accept="image/*;capture=camera" (change)="onFileSelect($event)">
</div>
<div class="d-grid gap-2 mt-2">
<button class="btn btn-lg btn-secondary" type="submit" style="background-color: #5b628f">{{loading ? 'Processing':'Process the photo'}}</button>
</div>
</form>
</div>
</div>
</div>
</ion-content>
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { IonicModule } from '@ionic/angular';
import { SkinDiseaseTakeImagePage } from './skin-disease-take-image.page';
describe('SkinDiseaseTakeImagePage', () => {
let component: SkinDiseaseTakeImagePage;
let fixture: ComponentFixture<SkinDiseaseTakeImagePage>;
beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
declarations: [ SkinDiseaseTakeImagePage ],
imports: [IonicModule.forRoot()]
}).compileComponents();
fixture = TestBed.createComponent(SkinDiseaseTakeImagePage);
component = fixture.componentInstance;
fixture.detectChanges();
}));
it('should create', () => {
expect(component).toBeTruthy();
});
});
import { Component, OnInit } from '@angular/core';
import {PythonBackendService} from "../core/python-backend.service";
import {FormBuilder, FormGroup} from "@angular/forms";
import {Router} from "@angular/router";
@Component({
selector: 'app-skin-disease-take-image',
templateUrl: './skin-disease-take-image.page.html',
styleUrls: ['./skin-disease-take-image.page.scss'],
})
export class SkinDiseaseTakeImagePage implements OnInit {
uploadForm: FormGroup;
imageSrc: any;
public prediction: string;
loading = false;
constructor(
private pythonBackendService: PythonBackendService,
private formBuilder: FormBuilder,
private router: Router
) { }
ngOnInit() {
this.uploadForm = this.formBuilder.group({
file: ['']
});
}
onFileSelect(event) {
if (event.target.files.length > 0) {
const file = event.target.files[0];
this.uploadForm.get('file').setValue(file);
const reader = new FileReader();
reader.onload = e => this.imageSrc = reader.result;
reader.readAsDataURL(file);
}
}
onSubmit() {
const formData = new FormData();
formData.append('file', this.uploadForm.get('file').value);
this.loading = true;
this.pythonBackendService.predictSkinDisease(formData)
.subscribe(res => {
console.log(res);
this.loading = false;
this.prediction = res;
this.router.navigate(['/skin-disease-result/'+res.pred]);
}, error => {
console.log(error);
});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment