Skip to content

Commit

Permalink
Merge pull request #3 from Nonhuman-Nonsense/albin
Browse files Browse the repository at this point in the history
Albin
  • Loading branch information
albin-karlsson committed Apr 20, 2024
2 parents 5b058ac + 9a4bfae commit cfb1c9e
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 75 deletions.
28 changes: 25 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
.env
.DS_Store
node_modules
client
server
build

# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
23 changes: 0 additions & 23 deletions client/.gitignore

This file was deleted.

Binary file added client/public/images/foods/lollypop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions client/src/components/AudioOutput.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import React from "react";

function AudioOutput() {
return <></>;
}

export default AudioOutput;
12 changes: 12 additions & 0 deletions client/src/components/ConversationControls.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from "react";

function ConversationControls({ isPaused, onPauseResume, onSkipForward }) {
return (
<div style={{ pointerEvents: "auto" }}>
<button onClick={onPauseResume}>{isPaused ? "Resume" : "Pause"}</button>
<button onClick={onSkipForward}>Skip forward</button>
</div>
);
}

export default ConversationControls;
4 changes: 2 additions & 2 deletions client/src/components/Council.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Contact from "./Contact";
import Share from "./Share";
import ResetWarning from "./ResetWarning";
import Navbar from "./Navbar";
import TextOutput from "./TextOutput";
import Output from "./Output";
import useWindowSize from "../hooks/useWindowSize";

function Council({ options }) {
Expand Down Expand Up @@ -108,7 +108,7 @@ function Council({ options }) {
className="text-container"
style={{ justifyContent: "end" }}
>
<TextOutput conversation={conversation} />
<Output conversation={conversation} />
</div>
)}
<div style={foodsContainerStyle}>
Expand Down
82 changes: 82 additions & 0 deletions client/src/components/Output.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import React, { useState, useEffect } from "react";
import TextOutput from "./TextOutput";
import ConversationControls from "./ConversationControls";

function Output({ conversation }) {
const [currentMessageIndex, setCurrentMessageIndex] = useState(0);
const [currentSnippetIndex, setCurrentSnippetIndex] = useState(0);
const [currentMessageTextSnippet, setCurrentMessageTextSnippet] =
useState("");
const [initialize, setInitialize] = useState(true); // Flag to control initialization
const [isPaused, setIsPaused] = useState(false);

// Function to calculate the display time based on text length
const calculateDisplayTime = (text) => Math.max(3, text.length * 0.05);

function handlePauseResume() {
if (!isPaused) {
console.log("Pausing");
} else {
console.log("Resuming");
}

setIsPaused(!isPaused);
}

function handleSkipForward() {
// TODO: See if last message before skipping forward

console.log("Skipping forward");
}

useEffect(() => {
if (initialize && conversation.length > 0) {
setCurrentMessageIndex(0);
setCurrentSnippetIndex(0);
setInitialize(false); // Reset initialization flag after first setup
}
}, [conversation, initialize]);

useEffect(() => {
const processSnippets = () => {
if (conversation.length > currentMessageIndex) {
const snippets =
conversation[currentMessageIndex].text.split(/(?<=\.\s)/);
if (snippets.length > currentSnippetIndex) {
setCurrentMessageTextSnippet(snippets[currentSnippetIndex]);
const timeout = setTimeout(() => {
if (currentSnippetIndex < snippets.length - 1) {
setCurrentSnippetIndex(currentSnippetIndex + 1);
} else if (currentMessageIndex < conversation.length - 1) {
setCurrentMessageIndex(currentMessageIndex + 1);
setCurrentSnippetIndex(0);
}
}, calculateDisplayTime(snippets[currentSnippetIndex]) * 1000);
return () => clearTimeout(timeout);
}
}
};

processSnippets();
}, [currentMessageIndex, currentSnippetIndex, conversation]);

return (
<div>
<h2>
Speaker:{" "}
{conversation.length > 0
? conversation[currentMessageIndex].speaker
: ""}
</h2>
<TextOutput currentMessageTextSnippet={currentMessageTextSnippet} />
<AudioOutput />
<ConversationControls
isPaused={isPaused}
onPauseResume={handlePauseResume}
onSkipForward={handleSkipForward}
/>
</div>
);
}

export default Output;
49 changes: 2 additions & 47 deletions client/src/components/TextOutput.jsx
Original file line number Diff line number Diff line change
@@ -1,58 +1,13 @@
import React, { useState, useEffect } from "react";
import React from "react";

function TextOutput({ conversation }) {
const [currentMessageIndex, setCurrentMessageIndex] = useState(0);
const [currentSnippetIndex, setCurrentSnippetIndex] = useState(0);
const [currentMessageTextSnippet, setCurrentMessageTextSnippet] =
useState("");
const [initialize, setInitialize] = useState(true); // Flag to control initialization
function TextOutput({ currentMessageTextSnippet }) {
const textOutputStyle = {
fontFamily: "Arial, sans-serif",
backgroundColor: "rgba(0,0,0,0.7)",
};

// Function to calculate the display time based on text length
const calculateDisplayTime = (text) => Math.max(3, text.length * 0.05);

useEffect(() => {
if (initialize && conversation.length > 0) {
setCurrentMessageIndex(0);
setCurrentSnippetIndex(0);
setInitialize(false); // Reset initialization flag after first setup
}
}, [conversation, initialize]);

useEffect(() => {
const processSnippets = () => {
if (conversation.length > currentMessageIndex) {
const snippets =
conversation[currentMessageIndex].text.split(/(?<=\.\s)/);
if (snippets.length > currentSnippetIndex) {
setCurrentMessageTextSnippet(snippets[currentSnippetIndex]);
const timeout = setTimeout(() => {
if (currentSnippetIndex < snippets.length - 1) {
setCurrentSnippetIndex(currentSnippetIndex + 1);
} else if (currentMessageIndex < conversation.length - 1) {
setCurrentMessageIndex(currentMessageIndex + 1);
setCurrentSnippetIndex(0);
}
}, calculateDisplayTime(snippets[currentSnippetIndex]) * 1000);
return () => clearTimeout(timeout);
}
}
};

processSnippets();
}, [currentMessageIndex, currentSnippetIndex, conversation]);

return (
<div style={{ textAlign: "center", width: "75%" }}>
<h2 style={textOutputStyle}>
Speaking:{" "}
{conversation.length > 0
? conversation[currentMessageIndex].speaker
: ""}
</h2>
<h2 style={textOutputStyle}>{currentMessageTextSnippet || ""}</h2>
</div>
);
Expand Down
11 changes: 11 additions & 0 deletions client/src/global-options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"gptModel": "gpt-3.5-turbo-1106",
"temperature": 1,
"maxTokens": 200,
"frequency_penalty": 0,
"presence_penalty": 0,
"trimSentance": false,
"trimParagraph": true,
"show_trimmed": true,
"conversationMaxLength": 10
}

0 comments on commit cfb1c9e

Please sign in to comment.