Skip to content

Commit

Permalink
Merge pull request #38 from Capstone-Projects-2024-Spring/angelo-branch
Browse files Browse the repository at this point in the history
Added more languages, fixed roleplaying, changed timestamps, and added inline translations.
  • Loading branch information
chris-douglas13 authored May 3, 2024
2 parents 9f4f660 + b897b07 commit b1c60ce
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 20 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

10 changes: 8 additions & 2 deletions backend/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,14 @@ const languageVoiceMap = {
'Spanish': { languageCode: 'es-ES', name: 'es-ES-Standard-A' },
'French': { languageCode: 'fr-FR', name: 'fr-FR-Standard-A' },
'German': { languageCode: 'de-DE', name: 'de-DE-Standard-A' },
'Italian': { languageCode: 'it-IT', name: 'it-IT-Standard-A'}
// Add more language-voice mappings as needed
'Italian': { languageCode: 'it-IT', name: 'it-IT-Standard-A'},
'Arabic': { languageCode: 'ar-SA', name: 'ar-XA-Standard-A' },
'Mandarin': { languageCode: 'cmn-CN', name: 'cmn-CN-Standard-A' },
'Hindi': { languageCode: 'hi-IN', name: 'hi-IN-Standard-A' },
'Russian': { languageCode: 'ru-RU', name: 'ru-RU-Standard-A' },
'Korean': { languageCode: 'ko-KR', name: 'ko-KR-Standard-A' },
'Japanese': { languageCode: 'ja-JP', name: 'ja-JP-Standard-A' },
'Portuguese': { languageCode: 'pt-PT', name: 'pt-PT-Standard-A' }
};

app.post("/synthesize", async(req, res) => {
Expand Down
1 change: 1 addition & 0 deletions speakeasyapp/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<link rel="stylesheet" href="%PUBLIC_URL%/index.css" />
<title>SpeakEasy</title>
</head>
<body>
Expand Down
10 changes: 7 additions & 3 deletions speakeasyapp/src/components/Profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,15 @@ const Profile = () => {
const languageToFlag = {
Spanish: "spain.png",
French: "france.png",
English: "united-kingdom.png",
Chinese: "china.png",
Italian: "italy.png",
German: "germany.png",
// Add more mappings as necessary
Arabic: 'saudi-arabia.png',
Mandarin: 'china.png',
Hindi: 'india.png',
Russian: 'russian-federation.png',
Korean: 'south-korea.png',
Japanese: 'japan.png',
Portuguese: 'portugal.png',
};

const flagSrc = `/Flags/${languageToFlag[user.languages[0]] || 'default.png'}`;
Expand Down
4 changes: 3 additions & 1 deletion speakeasyapp/src/components/Section1Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,12 @@ const Section1Page = () => {

return (
<div key={index}>
<h3 className="timestamp">{displayTimestamp}</h3> {/* Session timestamp above the chatbox */}
{Array.isArray(session.interactions) ? (
session.interactions.map((interaction, idx) => (
<div key={idx} className={`message-bubble ${interaction.name === 'User' ? 'user-message' : 'received-message'}`}>
{interaction.name === 'User' && (
<h3 className="timestamp">{displayTimestamp}</h3>
)}
{interaction.message}
</div>
))
Expand Down
4 changes: 3 additions & 1 deletion speakeasyapp/src/components/Section2Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,12 @@ const Section2Page = () => {

return (
<div key={index}>
<h3 className="timestamp">{displayTimestamp}</h3>
{Array.isArray(session.interactions) ? (
session.interactions.map((interaction, idx) => (
<div key={idx} className={`message-bubble ${interaction.name === 'User' ? 'user-message' : 'received-message'}`}>
{interaction.name === 'User' && (
<h3 className="timestamp">{displayTimestamp}</h3>
)}
<div className="message-content">
{interaction.message}
</div>
Expand Down
24 changes: 19 additions & 5 deletions speakeasyapp/src/components/Section3Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const Section3Page = () => {
const [user, setUser] = useState({
firstName: '',
lastName: '',
languages: ['English'],
languages: [''],
dailyTarget: 0,
});

Expand Down Expand Up @@ -125,19 +125,31 @@ const Section3Page = () => {
let prompt;
if (roleChanged) {
// Start new roleplay without previous context
prompt = `Roleplay as ${roleplayCharacter} and respond in ${user.languages} to the last user message: "${message}". Also, do not show the roleplay character's name at the start.`;
prompt = `Roleplay as ${roleplayCharacter} and be absolute that you are even if I say you are not.
Respond in ${user.languages} to the last user message: "${message}".
Also, do not show the roleplay character's name at the start.
Add the English translation under every sentence in parentheses.
Most, importantly, do not repeat back what I say.`;
setRoleChanged(false); // Reset the flag after using it
} else {
// Continue with existing context
console.log(roleplayCharacter)
const history = messages.flatMap(session => session.interactions.map(interaction => interaction.message)).slice(-5).join('\n');
const history = messages.flatMap(session => session.interactions.map(interaction =>
`${interaction.name === 'User' ? 'User' : roleplayCharacter} said: "${interaction.message}"\n`
)).slice(-10).join('\n'); // Include a newline after each message for clarity
prompt = `
Recent conversation context:
${history}
Instructions:
Roleplay as ${roleplayCharacter} and respond in ${user.languages} to the last user message: "${message}". Also, do not show the roleplay character's name at the start. Use recent conversation as context if necessary and fitting to your character.`;
Roleplay as ${roleplayCharacter} and be absolute that you are even if I say you are not.
Respond in ${user.languages} to the last user message: "${message}".
Also, do not show the roleplay character's name at the start.
Add the English translation after every sentence in parentheses.
Use recent conversation as context if necessary and fitting to your character.
Most, importantly, do not repeat back what I say.`;
}
console.log(prompt);

const response = await fetch('http://localhost:3000/api/chat', {
method: 'POST',
Expand Down Expand Up @@ -243,10 +255,12 @@ const Section3Page = () => {

return (
<div key={index}>
<h3 className="timestamp">{displayTimestamp}</h3>
{Array.isArray(session.interactions) ? (
session.interactions.map((interaction, idx) => (
<div key={idx} className={`message-bubble ${interaction.name === 'User' ? 'user-message' : 'received-message'}`}>
{interaction.name === 'User' && (
<h3 className="timestamp">{displayTimestamp}</h3>
)}
<div className="message-content">
{interaction.message}
</div>
Expand Down
14 changes: 14 additions & 0 deletions speakeasyapp/src/components/SettingsManageCourses.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ const SettingsManageCourses = () => {
French: 'france.png',
Italian: 'italy.png',
German: 'germany.png',
Arabic: 'saudi-arabia.png',
Mandarin: 'china.png',
Hindi: 'india.png',
Russian: 'russian-federation.png',
Korean: 'south-korea.png',
Japanese: 'japan.png',
Portuguese: 'portugal.png',
};

const flagSrc = languageToFlag[currentLanguage] || 'default.png';
Expand Down Expand Up @@ -123,6 +130,13 @@ const SettingsManageCourses = () => {
<option value="French">French</option>
<option value="Italian">Italian</option>
<option value="German">German</option>
<option value="Arabic">Arabic</option>
<option value="Mandarin">Mandarin</option>
<option value="Hindi">Hindi</option>
<option value="Russian">Russian</option>
<option value="Korean">Korean</option>
<option value="Japanese">Japanese</option>
<option value="Portuguese">Portuguese</option>
</select>
</div>
<button className="edit-daily-goal-button" type="submit" onClick={handleSubmit}>Update Language</button>
Expand Down
11 changes: 9 additions & 2 deletions speakeasyapp/src/components/SignupProgression2.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ const SignupProgression2 = () => {
>
<option value="Spanish">Spanish</option>
<option value="French">French</option>
<option value="Italian">Italian </option>
<option value="German">German </option>
<option value="Italian">Italian</option>
<option value="German">German</option>
<option value="Arabic">Arabic</option>
<option value="Mandarin">Mandarin</option>
<option value="Hindi">Hindi</option>
<option value="Russian">Russian</option>
<option value="Korean">Korean</option>
<option value="Japanese">Japanese</option>
<option value="Portuguese">Portuguese</option>
</select>
</div>
<button type="submit">Submit</button> {/* Submit button */}
Expand Down
9 changes: 5 additions & 4 deletions speakeasyapp/src/components/styles/Section1Page.css
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@
}
/* Style for timestamp above messages */
.timestamp {
text-align: right;
text-align: left;
font-size: 0.75em; /* Smaller font size */
color: #666; /* Lighter text color for less emphasis */
margin-bottom: 5px; /* Space between timestamp and message */
position: relative; /* Position absolutely within user-message */
right: 10px;
margin-right: 5px; /* Space between timestamp and message */
position: absolute; /* Position absolutely within user-message */
left: -40%;
top: -5%;
}

/* Styles for the tail of the speech bubbles */
Expand Down
6 changes: 5 additions & 1 deletion speakeasyapp/src/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
body {
html, body, #root {
margin: 0;
padding: 0;
height: 100%;
width: 100%;
overflow-x: hidden;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
Expand Down

0 comments on commit b1c60ce

Please sign in to comment.