Skip to content

Commit

Permalink
import glowbom files
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-i committed Apr 18, 2023
1 parent fdc6378 commit b97f1dd
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 33 deletions.
2 changes: 1 addition & 1 deletion app/assets/talk.glowbom
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"title":"Glowby","main_color":"Black","conclusion":"Please send us your information and we'll come back to you shortly!","start_over":"Glowby","show_number_result":true,"show_percentage_result":true,"voice":true,"questions":[{"title":"","description":"Hello","buttonsTexts":["Hello!","Hi!","Hi there!","Hey, What's up?"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"How's it going?","buttonsTexts":["I'm ok.","I'm doing quite well, thank you.","Pretty good. How goes it for you?","I'm good, thanks for asking!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"What's up?","buttonsTexts":["Not much. Just enjoying my time on this sim.","You just summed up my worldview.","Nothing really, just keeping busy.","I can't tell you!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]}],"dnsgs":true}
{"title":"Glowby","main_color":"Black","conclusion":"Please send us your information and we'll come back to you shortly!","start_over":"Glowby","show_number_result":true,"show_percentage_result":true,"voice":true,"questions":[{"title":"","description":"Hello","buttonsTexts":["Hello!","Hi!","Hi there!","Hey, What's up?"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"How's it going?","buttonsTexts":["I'm ok.","I'm doing quite well, thank you.","Pretty good. How goes it for you?","I'm good, thanks for asking!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]},{"title":"","description":"What's up?","buttonsTexts":["Not much. Just enjoying my time on this sim.","You just summed up my worldview.","Nothing really, just keeping busy.","I can't tell you!"],"buttonAnswers":[0,0,0,0],"answersCount":0,"goIndexes":[2,2,2,2],"answerPicture":"","answerPictureDelay":0,"goConditions":[],"heroValues":[],"picturesSpriteNames":["","","","","",""]}],"dnsgs":false}
10 changes: 6 additions & 4 deletions app/lib/ai_settings_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import 'package:flutter/material.dart';
import 'package:web/openai_api.dart';
import 'package:web/text_to_speech.dart';

import 'chat_screen.dart';

class AiSettingsDialog extends StatefulWidget {
final Function(bool) onVoiceEnabledChanged;

Expand All @@ -12,11 +10,15 @@ class AiSettingsDialog extends StatefulWidget {
static String get selectedLanguage =>
_AiSettingsDialogState._selectedLanguage;

static bool get voiceEnabled => _AiSettingsDialogState._voiceEnabled;

@override
_AiSettingsDialogState createState() => _AiSettingsDialogState();
}

class _AiSettingsDialogState extends State<AiSettingsDialog> {
static bool _voiceEnabled = true;

String _selectedModel = OpenAI_API.model;
String _systemPrompt = OpenAI_API.systemPrompt;
final TextEditingController _systemPromptController = TextEditingController();
Expand Down Expand Up @@ -174,10 +176,10 @@ class _AiSettingsDialogState extends State<AiSettingsDialog> {
),
CheckboxListTile(
title: Text('Enable voice'),
value: ChatScreenState.voiceEnabled,
value: _AiSettingsDialogState._voiceEnabled,
onChanged: (bool? value) {
setState(() {
ChatScreenState.voiceEnabled = value!;
_AiSettingsDialogState._voiceEnabled = value!;
});
widget.onVoiceEnabledChanged(value!);
},
Expand Down
12 changes: 6 additions & 6 deletions app/lib/chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ class ChatScreen extends StatefulWidget {
ChatScreen(this._name, this._questions, this._voice);

@override
ChatScreenState createState() => ChatScreenState();
_ChatScreenState createState() => _ChatScreenState();
}

class ChatScreenState extends State<ChatScreen> {
static bool voiceEnabled = false;
class _ChatScreenState extends State<ChatScreen> {
bool _voiceEnabled = true;
void updateVoiceEnabled(bool value) {
setState(() {
voiceEnabled = value;
_voiceEnabled = value;
});
}

Expand All @@ -34,15 +34,15 @@ class ChatScreenState extends State<ChatScreen> {
@override
void initState() {
super.initState();
voiceEnabled = widget._voice;
_voiceEnabled = widget._voice;
OpenAI_API.loadOat().then((_) {
setState(() {});
});
}

// Refresh the chat screen and handle text-to-speech functionality
void refresh() {
if (widget._voice && voiceEnabled) {
if (widget._voice && _voiceEnabled) {
try {
if (_messages.isNotEmpty && _messages[0].userId == '007') {
textToSpeech.speakText(_messages[0].text,
Expand Down
2 changes: 1 addition & 1 deletion app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import './preset_talk.dart';

// Entry point of the application
// runApp starts the Flutter app by inflating the given widget and attaching it to the screen
void main() => runApp(Talk(null));
void main() => runApp(TalkApp());
57 changes: 36 additions & 21 deletions app/lib/preset_talk.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ import 'package:flutter/material.dart';
import 'color_utils.dart';
import 'chat_screen.dart';

var _content;

class _TalkState extends State<Talk> {
var _appScreen = 'Loading';

String? _title;
String? _mainColor;
bool? _voice = false;
List<Map<String, Object>> _questions = [];
GlobalKey<ChatScreenState> chatScreenKey = GlobalKey();

_TalkState(this._content);

var _content;
_TalkState();

Future<dynamic> loadContentFromAssets() async {
String data =
Expand All @@ -32,8 +31,9 @@ class _TalkState extends State<Talk> {
}

void initializeTalkState() {
print('content: $_content');
if (_content != null) {
_questions = _content['questions'];
_questions = buildQuestions(_content['questions']);
_title = _content['title'];
_mainColor = _content['main_color'] ?? 'Blue';
_voice = _content['voice'] ?? false;
Expand Down Expand Up @@ -63,19 +63,8 @@ class _TalkState extends State<Talk> {
if (fileBytes != null) {
String content =
utf8.decode(fileBytes); // Decode the Uint8List to a String
Map<String, dynamic> fileContent = json.decode(content);

// Do something with the file content, e.g., update the questions
setState(() {
_content = fileContent;
_title = _content['title'];
_mainColor = _content['main_color'] ?? 'Blue';
_voice = _content['voice'] ?? false;
_questions = buildQuestions(_content['questions']);
});

print(_content);
print('name = ${_content['start_over']}');
_content = json.decode(content);
keyIndex.value += 1;
}
}
} catch (e) {
Expand Down Expand Up @@ -181,14 +170,40 @@ class _TalkState extends State<Talk> {
}
}

ValueNotifier<int> keyIndex = ValueNotifier<int>(0);

// A StatefulWidget that represents the main Talk widget.
class Talk extends StatefulWidget {
final _content;
final Key key;

Talk(this._content);
Talk({required this.key});

@override
State<StatefulWidget> createState() {
return _TalkState(_content);
return _TalkState();
}
}

class TalkApp extends StatefulWidget {
@override
_TalkAppState createState() => _TalkAppState();
}

class _TalkAppState extends State<TalkApp> {
@override
void initState() {
super.initState();
keyIndex.addListener(() {
setState(() {});
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
home: Talk(
key: Key(keyIndex.value.toString()),
),
);
}
}

0 comments on commit b97f1dd

Please sign in to comment.