Skip to content
Open
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ dist-ssr
*.sln
*.sw?

client/node_modules
server/node_modules
# env
.env
Binary file added 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# Build and Deploy Your Own ChatGPT AI Application That Will Help You Code


# Build and Deploy Your Own ChatGPT AI with audio Application That Will Help You Code
## A Few Screenshots

![Open AI CodeGPT](https://i.ibb.co/LS4DRhb/image-257.png)

## To run this project

- cd to into server and
``
Run npm install
``

- cd to into client and
``
Run npm install
``

- Get your API KEY at https://beta.openai.com/account/api-keys

- Create .env file inside server folder and paste your generated key

#inside server
``
Run npm run server
``
#inside client
``
Run npm run dev
``

![Alt text](1.png?raw=true "Title")
![Alt text](2.PNG?raw=true "Title")

### Launch your development career with project-based coaching - https://www.jsmastery.pro
41 changes: 41 additions & 0 deletions client/assets/microphone-off.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions client/assets/microphone-on.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 41 additions & 0 deletions client/assets/microphone-svgrepo-com.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 4 additions & 2 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
</head>
<body>
<div id="app">
<div id="chat_container"></div>
<div class="chat_container" id="chat_container"></div>

<form>
<textarea name="prompt" rows="1" cols="1" placeholder="Ask codex..."></textarea>
<img id="micOn" src="assets/microphone-off.svg" alt="mic off" />
<img id="micOff" style="display: none;" src="assets/microphone-on.svg" alt="mic ff" />
<textarea id="prompt" name="prompt" rows="1" cols="1" placeholder="Ask codex..."></textarea>
<button type="submit"><img src="assets/send.svg" alt="send" />
</form>
</div>
Expand Down
92 changes: 91 additions & 1 deletion client/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const form = document.querySelector('form')
const chatContainer = document.querySelector('#chat_container')

let loadInterval
let speechRecognition = null;


function loader(element) {
element.textContent = ''
Expand Down Expand Up @@ -62,6 +64,85 @@ function chatStripe(isAi, value, uniqueId) {
)
}

function micControl(isRecording){

if(isRecording){
document.querySelector("#micOn").style.display = "none";
document.querySelector("#micOff").style.display = "inline";
}else{

document.querySelector("#micOn").style.display = "inline";
document.querySelector("#micOff").style.display = "none";
}
speechRecognition.stop();

}

function speechText(){
if ("webkitSpeechRecognition" in window) {
// Initialize webkitSpeechRecognition
speechRecognition = new webkitSpeechRecognition();

// String for the Final Transcript
let final_transcript = "";

// Set the properties for the Speech Recognition object
speechRecognition.continuous = false;
speechRecognition.interimResults = true;

// Callback Function for the onStart Event
speechRecognition.onstart = () => {
// Show the Status Element
micControl(true);
};
speechRecognition.onerror = () => {
// Hide the Status Element
micControl(false);
};
speechRecognition.onend = () => {
// Hide the Status Element
micControl(false);
};

speechRecognition.onresult = (event) => {
// Create the interim transcript string locally because we don't want it to persist like final transcript
let interim_transcript = "";

// Loop through the results from the speech recognition object.
for (let i = event.resultIndex; i < event.results.length; ++i) {
// If the result item is Final, add it to Final Transcript, Else add it to Interim transcript
if (event.results[i].isFinal) {
final_transcript += event.results[i][0].transcript;
} else {
interim_transcript += event.results[i][0].transcript;
}
}

// Set the Final transcript and Interim transcript.
document.querySelector("#prompt").innerHTML = final_transcript+''+interim_transcript;
// var interim = document.querySelector("#interim").innerHTML = interim_transcript;
speechRecognition.stop();
};

} else {
console.log("Speech Recognition Not Available");
}
}

// Set the onClick property of the start button
document.querySelector("#micOn").onclick = () => {

speechText();
// Start the Speech Recognition
speechRecognition.start();
};
// Set the onClick property of the stop button
document.querySelector("#micOff").onclick = () => {
// Stop the Speech Recognition
speechText();
speechRecognition.stop();
};

const handleSubmit = async (e) => {
e.preventDefault()

Expand All @@ -72,6 +153,8 @@ const handleSubmit = async (e) => {

// to clear the textarea input
form.reset()
document.querySelector("#prompt").value= '';
micControl(false);

// bot's chatstripe
const uniqueId = generateUniqueId()
Expand All @@ -86,7 +169,7 @@ const handleSubmit = async (e) => {
// messageDiv.innerHTML = "..."
loader(messageDiv)

const response = await fetch('https://codex-im0y.onrender.com/', {
const response = await fetch('http://localhost:5000/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -104,17 +187,24 @@ const handleSubmit = async (e) => {
const parsedData = data.bot.trim() // trims any trailing spaces/'\n'

typeText(messageDiv, parsedData)

} else {
const err = await response.text()

messageDiv.innerHTML = "Something went wrong"
alert(err)
}

speechRecognition.abort();
speechRecognition.stop();
}



form.addEventListener('submit', handleSubmit)
form.addEventListener('keyup', (e) => {
if (e.keyCode === 13) {
handleSubmit(e)
}
speechRecognition.abort();
})
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ app.use(express.json())

app.get('/', async (req, res) => {
res.status(200).send({
message: 'Hello from CodeX!'
message: 'Hello from enhance CodeX!'
})
})

Expand Down