From a45ef36394282bf9d80c13dea34d243cd851900b Mon Sep 17 00:00:00 2001 From: Krish Shah Date: Fri, 5 May 2023 21:54:56 -0600 Subject: [PATCH 1/8] random uncommited changes --- client/src/components/Project.js | 115 ++++++++++++++++++------------- client/src/components/header.js | 37 +++++----- 2 files changed, 85 insertions(+), 67 deletions(-) diff --git a/client/src/components/Project.js b/client/src/components/Project.js index 2f1c5bd..fe34724 100644 --- a/client/src/components/Project.js +++ b/client/src/components/Project.js @@ -76,8 +76,7 @@ function Project() { const [curBeat, setCurBeat] = useState(beat1); const [play, { stop: stopBeat }] = useSound(curBeat); const [transcripts, setTranscripts] = useState(null); - const [outputData, setOutputData] = useState([]); - + const [rhymes, setRhymes] = useState(null); useEffect(() => { setupSocket(); @@ -125,43 +124,33 @@ function Project() { } }, [newTranscript]); - - async function getRhymes(lastWord) { - // const lastWord = transcript.split(" ").at(-1); - // //if the transcript has ever read in the current word - // console.log(rhymeSuggestions); - // console.log('im straight', transcript.split(" ").slice(0, -1), lastWord); - - //totalTranscript but as an array but i want to remove the element - if (totalTranscript.slice(0, -1).includes(lastWord)) { - console.log("IM GAY.") - rhymeSuggestions[lastWord] += 5; - } else { - rhymeSuggestions[lastWord] = 0; + useEffect(() => { + async function getRhymes(lastWord) { + // const lastWord = transcript.split(" ").at(-1); + // //if the transcript has ever read in the current word + // console.log(rhymeSuggestions); + // console.log('im straight', transcript.split(" ").slice(0, -1), lastWord); + + //totalTranscript but as an array but i want to remove the element + if (totalTranscript.slice(0, -1).includes(lastWord)) { + rhymeSuggestions[lastWord] += 5; + } else { + rhymeSuggestions[lastWord] = 0; + } + await fetch("https://api.datamuse.com/words?rel_rhy=" + lastWord) + .then((response) => response.json()) + .then((data) => + setRhymes( + data.slice( + rhymeSuggestions[lastWord], + rhymeSuggestions[lastWord] + 5 + ) + ) + ); } - fetch("https://api.datamuse.com/words?rel_rhy=" + lastWord) - .then((response) => response.json()) - .then((data) => - data - .slice(rhymeSuggestions[lastWord], rhymeSuggestions[lastWord] + 5) - .map((word, index) => { - // console.log(word.word); - /* - setOutputData([...outputData, { - word: lastWord, - suggestions: [...outputData[index].suggestions, word.word] - }]) - */ - }) - ); - } - /* - useEffect(() => { - getRhymes(); - console.log('outputData', outputData); + getRhymes(transcript.split(" ").at(-1)); }, [transcript]); - */ const fetchRecordings = async () => { const response = await fetch( @@ -287,9 +276,7 @@ function Project() { Ghostwriter
- Rapping is a form of poetry, one to ease the mind and provide clarity. - We are hacking the mental health space by giving literal poetic - justice to users around the world. + Your personalized AI freestyle assistant.
@@ -301,18 +288,51 @@ function Project() { {totalTranscript.map((singleTranscript, index) => (

{singleTranscript}

))} - {/*

{transcript}

*/} -
+

{transcript}

+ +

+ Rhymes +

+
+ {rhymes && + rhymes.map((rhyme) => { + return

{rhyme.word}

; + })} +
+ {/*
{transcript.split(" ").map((word) => ( -
+
))} -
+
*/}
{blob && blobUrl ? (
-
+
{transcripts ? (
diff --git a/client/src/components/header.js b/client/src/components/header.js index 7f4d151..5c8847a 100644 --- a/client/src/components/header.js +++ b/client/src/components/header.js @@ -1,38 +1,33 @@ import Brightness4Icon from "@mui/icons-material/Brightness4"; import Brightness7Icon from "@mui/icons-material/Brightness7"; import { ColorModeContext } from "../Home.jsx"; -import {IconButton, useTheme, Link, Button, Stack} from "@mui/material"; -import {useContext} from "react"; +import { IconButton, useTheme, Link, Button, Stack } from "@mui/material"; +import { useContext } from "react"; import { HeaderWrapper } from "./styles"; import { AppBar, Toolbar } from "@mui/material"; // import { Link } from "react-router-dom"; // import Link from '@mui/material/Link'; - - - function Header() { const colorMode = useContext(ColorModeContext); const theme = useTheme(); return ( -
- +
- - {theme.palette.mode === "dark" ? ( - - ) : ( - - )} - - - HomePage - SocialPage - - - - + + {theme.palette.mode === "dark" ? ( + + ) : ( + + )} + + +
); } From 2e4cc692f793e7bc981492fc0a2f5f9094bb2fd8 Mon Sep 17 00:00:00 2001 From: Krish Shah Date: Sat, 6 May 2023 01:52:40 -0700 Subject: [PATCH 2/8] make it work again --- .gitignore | 1 + client/src/components/Project.js | 8 +++----- server/.env | 3 ++- server/index.js | 5 ++++- server/package-lock.json | 14 ++++++++++++++ server/package.json | 1 + 6 files changed, 25 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index ab14592..a431b09 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ build/* */build/* .idea +server/key.json diff --git a/client/src/components/Project.js b/client/src/components/Project.js index fe34724..0eae894 100644 --- a/client/src/components/Project.js +++ b/client/src/components/Project.js @@ -54,7 +54,7 @@ const downsampleBuffer = (buffer, sampleRate, outSampleRate) => { const sendAudioFile = async (file, lyrics) => { const formData = new URLSearchParams({ recording: file, lyrics: lyrics }); - return fetch("https://prod-ghostwriter.herokuapp.com/api/recordings", { + return fetch("http://localhost:3001/api/recordings", { method: "POST", body: formData, headers: { @@ -153,16 +153,14 @@ function Project() { }, [transcript]); const fetchRecordings = async () => { - const response = await fetch( - "https://prod-ghostwriter.herokuapp.com/api/get/recordings" - ); + const response = await fetch("http://localhost:3001/api/get/recordings"); const data = await response.json(); setTranscripts(data); console.log(data); }; const setupSocket = () => { - socket.current = io("https://prod-ghostwriter.herokuapp.com/", { + socket.current = io("http://localhost:3001/", { reconnection: true, reconnectionDelay: 1000, reconnectionDelayMax: 5000, diff --git a/server/.env b/server/.env index b75d7a1..73f0351 100644 --- a/server/.env +++ b/server/.env @@ -1,3 +1,4 @@ export GOOGLE_APPLICATION_CREDENTIALS="./key.json" api_key=L$0JfnssHJGTks -COHERE_API_KEY=$api_key \ No newline at end of file +COHERE_API_KEY=$api_key +DATABASE_URL="postgresql://ghostwriter:redbullgivesyouwings@upper-calf-6800.7tt.cockroachlabs.cloud:26257/defaultdb?sslmode=verify-full" \ No newline at end of file diff --git a/server/index.js b/server/index.js index ebf1930..75293da 100644 --- a/server/index.js +++ b/server/index.js @@ -12,6 +12,7 @@ const { Sequelize } = require("sequelize-cockroachdb"); const bodyParser = require("body-parser"); const speech = require("@google-cloud/speech"); const client = new speech.SpeechClient(); +const dotenv = require("dotenv").config(); // Configure Transcription Request const request = { @@ -35,7 +36,9 @@ app.use(cors()); app.get("/", (req, res) => res.send("Hello World!")); -const sequelize = new Sequelize(process.env.DATABASE_URL); +const sequelize = new Sequelize(process.env.DATABASE_URL, { + dialect: "postgres", +}); const Recording = sequelize.define("transcripts", { id: { diff --git a/server/package-lock.json b/server/package-lock.json index 2a20b57..dcf6acb 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -12,6 +12,7 @@ "@google-cloud/speech": "^5.1.0", "body-parser": "^1.20.1", "cors": "^2.8.5", + "dotenv": "^16.0.3", "express": "^4.18.2", "nodemon": "^2.0.20", "sequelize-cockroachdb": "^6.0.5", @@ -670,6 +671,14 @@ "npm": "1.2.8000 || >= 1.4.16" } }, + "node_modules/dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==", + "engines": { + "node": ">=12" + } + }, "node_modules/dottie": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", @@ -3548,6 +3557,11 @@ "resolved": "https://registry.npmjs.org/destroy/-/destroy-1.2.0.tgz", "integrity": "sha512-2sJGJTaXIIaR1w4iJSNoN0hnMY7Gpc/n8D4qSCJw8QqFWXf7cuAgnEHxBpweaVcPevC2l3KpjYCx3NypQQgaJg==" }, + "dotenv": { + "version": "16.0.3", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.0.3.tgz", + "integrity": "sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==" + }, "dottie": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/dottie/-/dottie-2.0.2.tgz", diff --git a/server/package.json b/server/package.json index 123aaa9..917a5e7 100644 --- a/server/package.json +++ b/server/package.json @@ -13,6 +13,7 @@ "@google-cloud/speech": "^5.1.0", "body-parser": "^1.20.1", "cors": "^2.8.5", + "dotenv": "^16.0.3", "express": "^4.18.2", "nodemon": "^2.0.20", "sequelize-cockroachdb": "^6.0.5", From 57f43e1a8c2519b5d846415f8911fc568a65a2aa Mon Sep 17 00:00:00 2001 From: Krish Shah Date: Sat, 6 May 2023 02:13:40 -0700 Subject: [PATCH 3/8] add key.json --- .gitignore | 1 - server/key.json | 12 ++++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 server/key.json diff --git a/.gitignore b/.gitignore index a431b09..ab14592 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,3 @@ node_modules/ build/* */build/* .idea -server/key.json diff --git a/server/key.json b/server/key.json new file mode 100644 index 0000000..2877651 --- /dev/null +++ b/server/key.json @@ -0,0 +1,12 @@ +{ + "type": "service_account", + "project_id": "crested-acumen-385615", + "private_key_id": "d8b279e5c54d252a8f8c8c3a31531a113d8b6a2a", + "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDEGe67lXfAxk8Q\ntvDnBMF02VypkIo8pBnaHBmUUw+Yn7RSF8O6y5gAC9ewfgzJRzTNAzhI7BWjn45b\nozyN4JcmR9O96Jxhcsw00b0rc6wQIlt4Byx+S888orwGRVj9XKrTEI9OlyS2D6nC\na8fWZb8IA3y91jxUTmgohcfIzG/OSGqrZ+c2MQUgT0EwvQbjoeo5Jrmf3qA+ls0s\nFUzN8QxDKMfR1dX3w45p8QGc5Qp/rB8RmlYLyoC1tfuVY/TKyFNZTNvg9UT1J+So\n3YhJKsHd/kqEGrJrZzOdZPt9JtFgDWMoUhLydY5BNMGLrZDFh/A+BSi1z30Uk0Ox\nrxtFAxb/AgMBAAECggEADFRXErs4jsnJIdNmvReq9CZQcabRUjO9Hl4C67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dCIK/9rxTbhUf+d3KLwtyP1YtO15DAVSwbTu2FIWNXoLbQCT\nO5QzmOgsXBk506+xTKQ7w6FIbfJb8VOaohfKaNl6YUNXJanl8ELP169B0uHyjR2T\nVah9N1AbmX72VoYNYznLXviI\n-----END PRIVATE KEY-----\n", + "client_email": "ghostwriter@crested-acumen-385615.iam.gserviceaccount.com", + "client_id": "107815173863781773666", + "auth_uri": "https://accounts.google.com/o/oauth2/auth", + "token_uri": "https://oauth2.googleapis.com/token", + "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", + "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/ghostwriter%40crested-acumen-385615.iam.gserviceaccount.com" +} From e6b76b868cc1ba5f497c6ae5689e12f89f4e7b8f Mon Sep 17 00:00:00 2001 From: Krish Shah Date: Sat, 6 May 2023 02:24:43 -0700 Subject: [PATCH 4/8] change port --- client/src/components/Project.js | 8 +++++--- server/index.js | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/client/src/components/Project.js b/client/src/components/Project.js index 0eae894..c2af226 100644 --- a/client/src/components/Project.js +++ b/client/src/components/Project.js @@ -54,7 +54,7 @@ const downsampleBuffer = (buffer, sampleRate, outSampleRate) => { const sendAudioFile = async (file, lyrics) => { const formData = new URLSearchParams({ recording: file, lyrics: lyrics }); - return fetch("http://localhost:3001/api/recordings", { + return fetch("http://ghostwriter-production.up.railway.app/api/recordings", { method: "POST", body: formData, headers: { @@ -153,14 +153,16 @@ function Project() { }, [transcript]); const fetchRecordings = async () => { - const response = await fetch("http://localhost:3001/api/get/recordings"); + const response = await fetch( + "http://ghostwriter-production.up.railway.app/api/get/recordings" + ); const data = await response.json(); setTranscripts(data); console.log(data); }; const setupSocket = () => { - socket.current = io("http://localhost:3001/", { + socket.current = io("http://ghostwriter-production.up.railway.app/", { reconnection: true, reconnectionDelay: 1000, reconnectionDelayMax: 5000, diff --git a/server/index.js b/server/index.js index 75293da..4909332 100644 --- a/server/index.js +++ b/server/index.js @@ -1,7 +1,7 @@ const express = require("express"); const app = express(); const cors = require("cors"); -const port = 3001; +const port = process.env.PORT; const server = require("http").Server(app); const io = require("socket.io")(server, { cors: { From 7c28c4572110ba40dc03e4677df845eaf7cd0513 Mon Sep 17 00:00:00 2001 From: Krish Shah Date: Sat, 6 May 2023 02:32:39 -0700 Subject: [PATCH 5/8] add readme and dev port --- README.md | 8 +++++++- server/index.js | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dceb217..58119ac 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -# Western9Hackathon \ No newline at end of file +# Western9Hackathon + +Krish from the future here, wanted to add a couple of notes for this project: + +- client is hosted on firebase +- server is hosted on railway. Our trial runs out on about May 25th. We can't use vercel because this is repo lives in a team for which we need to pay for vercel. +- to save time, I added all env variables to the repo, but I know that's not a good practice. Consequently I have made this repo private for now. diff --git a/server/index.js b/server/index.js index 4909332..3167eed 100644 --- a/server/index.js +++ b/server/index.js @@ -1,7 +1,7 @@ const express = require("express"); const app = express(); const cors = require("cors"); -const port = process.env.PORT; +const port = process.env.PORT ?? 3001; const server = require("http").Server(app); const io = require("socket.io")(server, { cors: { From 30420ac2a281ca7ca05b69d5ac4df5445eeb0bf6 Mon Sep 17 00:00:00 2001 From: Krish Shah Date: Sat, 6 May 2023 02:37:20 -0700 Subject: [PATCH 6/8] remove dev port --- server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/index.js b/server/index.js index 3167eed..8e3e917 100644 --- a/server/index.js +++ b/server/index.js @@ -1,7 +1,7 @@ const express = require("express"); const app = express(); const cors = require("cors"); -const port = process.env.PORT ?? 3001; +const port = process.env.PORT; // exchange this with 3001 if you are on development mode const server = require("http").Server(app); const io = require("socket.io")(server, { cors: { From e22c393b50154286ff1655e4d599e6ddd416e054 Mon Sep 17 00:00:00 2001 From: Rohan Jagtap <70785034+rohan-jagtap04@users.noreply.github.com> Date: Sat, 6 May 2023 17:39:29 -0400 Subject: [PATCH 7/8] Update package.json --- server/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/package.json b/server/package.json index 917a5e7..90d7e73 100644 --- a/server/package.json +++ b/server/package.json @@ -5,7 +5,8 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon index.js" + "start": "nodemon index.js", + "build": "CI=false react-scripts build", }, "author": "", "license": "ISC", From 849d882892eccd56122720d0d5c781047e75f3fe Mon Sep 17 00:00:00 2001 From: Rohan Jagtap <70785034+rohan-jagtap04@users.noreply.github.com> Date: Sat, 6 May 2023 18:21:11 -0400 Subject: [PATCH 8/8] rohan is retarted --- client/package.json | 2 +- server/package.json | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/client/package.json b/client/package.json index 15b6f70..7e8d16c 100644 --- a/client/package.json +++ b/client/package.json @@ -21,7 +21,7 @@ }, "scripts": { "start": "react-scripts start", - "build": "react-scripts build", + "build": "CI=false react-scripts build", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/server/package.json b/server/package.json index 90d7e73..917a5e7 100644 --- a/server/package.json +++ b/server/package.json @@ -5,8 +5,7 @@ "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "start": "nodemon index.js", - "build": "CI=false react-scripts build", + "start": "nodemon index.js" }, "author": "", "license": "ISC",