Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions team_b/yappy/lib/env.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@ import 'package:envied/envied.dart';
// Run `flutter pub run build_runner build` to generate the env.g.dart file
@Envied(path: '.env')
abstract class Env {
@EnviedField(varName: 'OPENAI_API_KEY')
// Use this value instead for local testing: "_Env.apiKey;"
// Use the following values instead for local testing:
// "_Env.apiKey;"
// "_Env.awsRegion;"
// "_Env.awsAccessKey;"
// "_Env.awsSecretKey;"
// Otherwise, provide an API key within the application's settings while running

@EnviedField(varName: 'OPENAI_API_KEY')
static String apiKey = '';

@EnviedField(varName: 'AWS_REGION')
static const String awsRegion = '';

@EnviedField(varName: 'AWS_ACCESS_KEY', obfuscate: true)
static final String awsAccessKey = '';

@EnviedField(varName: 'AWS_SECRET_KEY', obfuscate: true)
static final String awsSecretKey = '';
}
115 changes: 47 additions & 68 deletions team_b/yappy/lib/industry_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import 'package:record/record.dart';
import 'package:share_plus/share_plus.dart';
import 'package:path_provider/path_provider.dart';
import 'package:permission_handler/permission_handler.dart';
import 'main.dart';
import 'services/openai_helper.dart';
import 'services/database_helper.dart';
import 'services/file_handler.dart';
import 'services/model_manager.dart';
import 'services/speech_state.dart';
import 'package:file_picker/file_picker.dart';
import 'package:yappy/services/restaurant_api_module.dart';
import 'transcript_dialog.dart';


class IndustryMenu extends StatefulWidget {
Expand Down Expand Up @@ -257,81 +259,58 @@ class _IndustryMenuState extends State<IndustryMenu> {
? null
: () async {
await widget.speechState.toggleRecording();
// When speechState.stop happens it needs to store the text in the database
// The new text file needs to get the USERID, create a new Transcript ID,
// The user will be asked to edit the text to ensure accuracy. After hitting save, the text will be saved to the database in the transcript table using the same transcript ID
if (widget.speechState.recordState ==
RecordState.stop) {
// Fetch the recorded text
String recordedText =
await widget.speechState.getRecordedText();

// Get the user ID (assuming you have a method to get the current user ID)

if (widget.speechState.recordState == RecordState.stop) {
// Fetch both transcripts
String localTranscript = widget.speechState.getRecordedText();
String awsTranscript = widget.speechState.getAwsRecordedText();
bool awsAvailable = await preferences.setBool('awsAvailable', true);

// Get the user ID
int userId = 0001;

// Create a new transcript ID
int transcriptId =
DateTime.now().millisecondsSinceEpoch;

// Show a dialog to edit the text
TextEditingController controller =
TextEditingController(text: recordedText);
int transcriptId = DateTime.now().millisecondsSinceEpoch;

// Show the dialog with both transcripts
if (!context.mounted) return;
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('Edit Transcript'),
content: TextField(
controller: controller,
decoration: InputDecoration(
hintText: 'Edit the transcript text'),
maxLines: null,
),
actions: [
TextButton(
onPressed: () async {
// Save the edited text to the database
await DatabaseHelper().saveTranscript(
userId: userId,
transcriptId: transcriptId,
text: controller.text,
industry: widget.title,
return TranscriptDialog(
localTranscript: localTranscript,
awsTranscript: awsTranscript,
awsAvailable: awsAvailable,
userId: userId,
transcriptId: transcriptId,
industry: widget.title,
onSave: (userId, transcriptId, text, industry) async {
// Save the selected transcript to the database
await DatabaseHelper().saveTranscript(
userId: userId,
transcriptId: transcriptId,
text: text,
industry: industry,
);

// Kick off the AI summarization process
var openAIHelper = OpenAIHelper();
String aiResponse = '';
try {
aiResponse = await openAIHelper.summarizeTranscription(
userId, industry, transcriptId
);
} catch (e) {
// Lets the user know that transcription summarization failed
if (context.mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to summarize transcription: $e')),
);
// Kick off the AI summarization process
var openAIHelper = OpenAIHelper();
String aiResponse = '';
try {
aiResponse = await openAIHelper
.summarizeTranscription(userId,
widget.title, transcriptId);
} catch (e) {
// Lets the user know that transcription summarization failed (likely because of a lack of OpenAI API key)
if (context.mounted) {
ScaffoldMessenger.of(context)
.showSnackBar(
SnackBar(
content: Text(
'Failed to summarize transcription: $e')),
);
}
}
// Place API hook here to parse aiResponse String and populate additional information based on industry:
debugPrint(
aiResponse); // not a necessary statement after implementation

if (!context.mounted) return;
Navigator.of(context).pop();
},
child: Text('Save'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
},
child: Text('Cancel'),
),
],
}
}

debugPrint(aiResponse);
},
);
},
);
Expand Down
34 changes: 28 additions & 6 deletions team_b/yappy/lib/main.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import 'dart:io' show Platform;
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:yappy/home_page.dart';
import 'package:yappy/services/database_helper.dart';
import 'package:dart_openai/dart_openai.dart';
import 'package:yappy/env.dart';
import 'package:sqflite_common_ffi/sqflite_ffi.dart';
import './home_page.dart';
import './services/database_helper.dart';
import './env.dart';
import './toast_widget.dart';
import 'package:provider/provider.dart';
import 'theme_provider.dart';
Expand All @@ -22,22 +24,42 @@ void main() async {

// Env file setup for local development
String apiKey = Env.apiKey;
String awsAccessKey = Env.awsAccessKey;
String awsSecretKey = Env.awsSecretKey;
String awsRegion = Env.awsRegion;
if (apiKey.isNotEmpty) {
OpenAI.apiKey = apiKey;
await preferences.setString('openai_api_key', apiKey);
}
if (awsRegion.isNotEmpty && awsAccessKey.isNotEmpty && awsSecretKey.isNotEmpty)
{
await preferences.setString('aws_access_key', awsAccessKey);
await preferences.setString('aws_secret_key', awsSecretKey);
await preferences.setString('aws_region', awsRegion);
await preferences.setBool('awsAvailable', true);
}
else
{
await preferences.setBool('awsAvailable', false);
}

if (Platform.isLinux || Platform.isWindows)
{
sqfliteFfiInit(); // Init ffi loader based on platform.
databaseFactory = databaseFactoryFfi;
}

await dbHelper.database;

WidgetsBinding.instance.addPostFrameCallback((_) {
// Shows dialog requesting an OpenAI API key if not set
// Shows dialog requesting a API keys if not set
if (apiKey.isEmpty) {
showDialog(
context: navigatorKey.currentContext!,
builder: (BuildContext context) {
return AlertDialog(
title: Text('OpenAI API Key Required'),
content: Text('Please add a valid OpenAI API key via the Settings menu.'),
title: Text('API Keys Required'),
content: Text('Please add valid API keys for OpenAI and AWS via the Settings menu.'),
actions: <Widget>[
TextButton(
child: Text('OK'),
Expand Down
Loading
Loading