diff --git a/frontend/lib/NonFuncTesting/NonFuncTestingPage.dart b/frontend/lib/NonFuncTesting/NonFuncTestingPage.dart new file mode 100644 index 0000000..f468749 --- /dev/null +++ b/frontend/lib/NonFuncTesting/NonFuncTestingPage.dart @@ -0,0 +1,46 @@ +import 'package:flutter/material.dart'; +import 'neural_net_service.dart'; // Import the service + +class ImageProcessingPage extends StatelessWidget { + const ImageProcessingPage({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Image Processing Page'), + ), + body: Center( + child: ElevatedButton( + onPressed: () async { + NeuralNetService neuralNetService = NeuralNetService(); + double avgResponseTime = await neuralNetService.processImagesAndGetAverageResponseTime(); + _showAverageResponseTime(context, avgResponseTime); + }, + child: const Text('Select Images and Get Avg Response Time'), + ), + ), + ); + } + + // Function to show average response time in a dialog + void _showAverageResponseTime(BuildContext context, double avgResponseTime) { + showDialog( + context: context, + builder: (BuildContext context) { + return AlertDialog( + title: const Text('Average Response Time'), + content: Text('Average Response Time: $avgResponseTime ms'), + actions: [ + TextButton( + child: const Text('OK'), + onPressed: () { + Navigator.of(context).pop(); + }, + ), + ], + ); + }, + ); + } +} diff --git a/frontend/lib/NonFuncTesting/neural_net_service.dart b/frontend/lib/NonFuncTesting/neural_net_service.dart new file mode 100644 index 0000000..1101171 --- /dev/null +++ b/frontend/lib/NonFuncTesting/neural_net_service.dart @@ -0,0 +1,52 @@ +import 'package:flutter/services.dart'; +import 'package:file_picker/file_picker.dart'; +import 'dart:async'; +import 'dart:io'; + +class NeuralNetService { + static const MethodChannel _channel = MethodChannel('neural_net_method_channel'); + + + Future processImagesAndGetAverageResponseTime() async { + List selectedFiles = []; + int totalResponseTime = 0; + try { + FilePickerResult? result = await FilePicker.platform.pickFiles( + type: FileType.image, + allowMultiple: true, + ); + if (result != null) { + selectedFiles = result.paths + .where((path) => path != null) + .map((path) => File(path!)) + .toList() + .take(10) + .toList(); + } else { + print('No files selected'); + return 0.0; + } + } on PlatformException catch (e) { + print('Error: ${e.message}'); + return 0.0; + } + + // Step 2: Calculate the average response time + for (var file in selectedFiles) { + final stopwatch = Stopwatch()..start(); + + try { + final imageBytes = await file.readAsBytes(); + await _channel.invokeMethod('get_mood', {'image': imageBytes}); + } on PlatformException catch (e) { + print('Error: ${e.message}'); + continue; + } + + stopwatch.stop(); + totalResponseTime += stopwatch.elapsedMilliseconds; + } + + return selectedFiles.isNotEmpty ? totalResponseTime / selectedFiles.length : 0.0; + } +} diff --git a/frontend/lib/main.dart b/frontend/lib/main.dart index d722d49..3e79d29 100644 --- a/frontend/lib/main.dart +++ b/frontend/lib/main.dart @@ -22,6 +22,8 @@ import 'package:frontend/pages/camera.dart'; import 'package:camera/camera.dart'; import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:frontend/pages/audio_player_page.dart'; +import 'package:frontend/NonFuncTesting/NonFuncTestingPage.dart'; + List cameras = []; @@ -74,6 +76,8 @@ class MyApp extends StatelessWidget { '/camerahelp': (context) => CameraVoiceHelpPage(), '/settings': (context) => SettingsPage(), '/audio': (context) => AudioPlayerPage(), + '/NonFunc': (context) => ImageProcessingPage() + }, theme: Provider.of(context).themeData, ), diff --git a/frontend/pubspec.yaml b/frontend/pubspec.yaml index 218169d..9c8c7d4 100644 --- a/frontend/pubspec.yaml +++ b/frontend/pubspec.yaml @@ -30,6 +30,7 @@ environment: dependencies: flutter: sdk: flutter + # The following adds the Cupertino Icons font to your application. # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.6 @@ -59,6 +60,7 @@ dependencies: permission_handler: ^10.3.0 sentiment_dart: sqflite_common_ffi: + file_picker: ^8.1.2