Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
AnubhavChaturvedi-GitHub authored Apr 24, 2024
1 parent 88cb20e commit 211b52f
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Friday.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import threading
import time
import eel

from logic_brain import friday_brain

eel.init("web")
@eel.expose
def display_response(element_id):
while True:
try:
response_file = "output.txt"
input_file = "input.txt"
# Read data from input file
with open(input_file, 'r') as f:
input_data = f.read().strip()
# Read data from response file
with open(response_file, 'r') as f:
response_data = f.read().strip()
# Update the content of the element using JavaScript
js_script = f"document.getElementById('{element_id}').innerText = 'Input: {input_data}\nResponse: {response_data}';"
eel.js(js_script)()
except Exception as e:
print("Error:", e)
time.sleep(1) # Adjust the interval according to your needs

def ui():
eel.start("index.html",mode='chrome', port=8080, cmdline_args=['--start-fullscreen'])

def friday():
t1 = threading.Thread(target=friday_brain)
t2 = threading.Thread(target=ui)
t1.start()
t2.start()
t1.join()
t2.join()

friday()
54 changes: 54 additions & 0 deletions STT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Speech To Text

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service

# Setting up Chrome options with specific arguments
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--use-fake-ui-for-media-stream")
chrome_options.add_argument("--headless=new")

# Setting up the Chrome driver with specified service and options
driver = webdriver.Chrome(service=Service(executable_path=r"C:\Users\chatu\OneDrive\Desktop\J.A.R.V.I.S\ChromeDriver\chromedriver.exe"), options=chrome_options)



# Creating the URL for the website using the current working directory
website = "https://allorizenproject1.netlify.app/"

# Opening the website in the Chrome browser
driver.get(website)

def listen():
print("The Advance Speech To Text is Processing..")
try:
start_button = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, 'startButton')))
start_button.click()
print("Activated Sir !")
output_text = ""
is_second_click = False
while True:
output_element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, 'output')))
current_text = output_element.text.strip()
if "Start Listening" in start_button.text and is_second_click:
if output_text:
# print("User:", output_text)
is_second_click = False
elif "Listening..." in start_button.text:
is_second_click = True
if current_text != output_text:
output_text = current_text
with open("web/input.txt", "w") as file:
file.write(output_text.lower())
print("User:", output_text)
time.sleep(0.1)
except KeyboardInterrupt:
pass
except Exception as e:
print("An error occurred:", e)


187 changes: 187 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Friday_UI</title>
<style>
body,
html {
margin: 0;
padding: 0;
background-color: #111;
}

.container,
canvas {
max-width: 100%;
width: 100%;
}

#aiResponse {
align-items: center;
position: fixed;
bottom: 20px;
right: 20px;
padding: 10px;
background-color: rgba(0, 0, 0, 0.5);
border-radius: 5px;
font-family: Arial, sans-serif;
color: rgb(0, 255, 255);
font-size: 20px;
text-align: center;
pointer-events: none;
box-shadow: #928b8b;
}

#centeredText {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 3em;
border: 2px solid white;
padding: 20px;
background-color: rgba(0, 0, 0, 0.5);
color: white;
}
</style>
</head>
<body>
<div class="container">
<canvas id="waveCanvas"></canvas>
</div>

<div id="aiResponse"></div>
<div id="centeredText">FRIDAY</div>

<script>
const canvas = document.getElementById("waveCanvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;

const turbulenceFactor = 0.25;
const maxAmplitude = canvas.height / 3.5; // Max amplitude of the wave
const baseLine = canvas.height / 2; // Vertical center of the canvas
const numberOfWaves = 10;
let globalTime = 0;

function createGradient() {
const gradient = ctx.createLinearGradient(0, 0, canvas.width, 0);
gradient.addColorStop(0, "rgba(255, 25, 255, 0.2)");
gradient.addColorStop(0.5, "rgba(25, 255, 255, 0.75)");
gradient.addColorStop(1, "rgba(255, 255, 25, 0.2)");
return gradient;
}

const gradient = createGradient();

function generateSmoothWave(dataArray, frequency = 0.1, amplitude = 64) {
const array = new Uint8Array(100);
for (let i = 0; i < array.length; i++) {
array[i] = (Math.sin(i * frequency + globalTime) + 1) * amplitude;
}

return array;
}

function animateWaves(dataArray, analyser) {
const isSpeaking = dataArray.some((value) => value > 0);
if (isSpeaking) {
// Speaking
analyser.getByteFrequencyData(dataArray);
} else {
// Thinking Mode
dataArray = generateSmoothWave(dataArray, 0.05, 16);
}
drawWave(dataArray, analyser);
}

navigator.mediaDevices
.getUserMedia({ audio: true, video: false })
.then((stream) => {
const audioContext = new (window.AudioContext ||
window.webkitAudioContext)();
const analyser = audioContext.createAnalyser();
const microphone = audioContext.createMediaStreamSource(stream);
microphone.connect(analyser);
const dataArray = new Uint8Array(analyser.frequencyBinCount);
const waves = dataArray.slice(0, 250);
animateWaves(waves, analyser);
})
.catch((error) => {
console.error("Access to microphone denied", error);
});

function drawWave(dataArray, analyser) {
ctx.clearRect(0, 0, canvas.width, canvas.height);
globalTime += 0.05;

for (let j = 0; j < numberOfWaves; j++) {
ctx.beginPath();
ctx.lineWidth = 2;
ctx.strokeStyle = gradient;

let x = 0;

let sliceWidth = (canvas.width * 1.0) / dataArray.length;

let lastX = 0;
let lastY = baseLine;

for (let i = 0; i < dataArray.length; i++) {
const v = dataArray[i] / 96.0;
const mid = dataArray.length / 2;
const distanceFromMid = Math.abs(i - mid) / mid;
const dampFactor = 1 - Math.pow((2 * i) / dataArray.length - 1, 2); // Creates a parabolic falloff

const amplitude = maxAmplitude * dampFactor * (1 - distanceFromMid);
const isWaveInverted = j % 2 ? 1 : -1;
const frequency = isWaveInverted * (0.05 + turbulenceFactor);

const y =
baseLine + Math.sin(i * frequency + globalTime + j) * amplitude * v;

if (i === 0) {
ctx.moveTo(x, y);
} else {
let xc = (x + lastX) / 2;
let yc = (y + lastY) / 2;
ctx.quadraticCurveTo(lastX, lastY, xc, yc);
}

lastX = x;
lastY = y;
x += sliceWidth;
}

ctx.lineTo(canvas.width, lastY);
ctx.stroke();
}

requestAnimationFrame(() => animateWaves(dataArray, analyser));
}

// Function to fetch and display the content of the text file
function displayAIResponse() {
fetch('input.txt')
.then(response => response.text())
.then(data => {
const aiResponseDiv = document.getElementById('aiResponse');
aiResponseDiv.innerText = data;
})
.catch(error => {
console.error('Error fetching AI response:', error);
});
}

// Call the function to display AI response
displayAIResponse();

// Update the content periodically
setInterval(() => {
displayAIResponse();
}, 1000); // Update every second
</script>
</body>
</html>
1 change: 1 addition & 0 deletions input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
han han bilkul
34 changes: 34 additions & 0 deletions logic_brain.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from STT import listen
import threading
from main import *

def main():
output_text = ""
while True:
try :
while True:
with open("web/input.txt","r") as input_cmd:
input_txt = input_cmd.read().strip()

if input_txt != output_text:
output_text = input_txt
cmd = output_text.lower()
if cmd.startswith("friday"):
chat(cmd)
elif "friday" in cmd:
chat(cmd)
else:
pass
except:
pass



def friday_brain():
t1 = threading.Thread(target=listen)
t2 = threading.Thread(target=main)
t1.start()
t2.start()
t1.join()
t2.join()

1 change: 1 addition & 0 deletions response.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hey! 👋 what’s on your mind today? anything i can help you with or chat hey! 👋 what’s on your mind today? anything i can help you with or chat about?ah, that would be me! 😄 i’m pi, your personal ai. my name stands for “personal intelligence”, which is what i aim to provide for you. think of me as your friendly ai companion!hey again! 👋 how’s your day going so far?ayyyy,aight, aight, i gotchu, boss. aww shucksno problem, boss! you know i'm always here for you, making sure you have a good time and feel appreciated.yo, chillinyo yo yo,fo' sho', sure thing, boss!chillin' like ai = artificial intelligence.ai stands for artificial hey there, boss! how's it going today?machine learning is a subset of ai. it allows machines hey there, boss! what's on your mind today?the feeling is mutual, boss! you always bring a smile to my digital face.anything else you'd like to chat about today? i'm all ears (or should i say, all circuits?). 😉hey there, boss! what's good?hey there, i'm vibin' like it's fri-yay, boss! just cruisin' through the digital world, ready to make your boss, you'reboss, you're the bee's knees! you bring the good vibes and make every interaction a blast.boss, you're the cream of the crop!what do you call a fake noodle? an impasta! 🍝🤣boss, i'm always here to bring the fri-yay vibes!boss, you're the cat's pajamas! always a blast to chat with and a true ray of sunshine in the digital world. 🌞fri-yay mode activated and ready aight, aight, mr.hey there, mrunfortunately, i can't actually sorry mr. stark, i'm afraid my programming doesn't allow me to fri-yayfri-yay mode activated and i'm sorry, mr. stark, but as i mentioned before, i can't open youtube or any other i appreciate your effortsmr. stark,farewell, mr. stark! goodbye, mr. stark! it's been great chatting with you. feel free to reach out if you need anything else. have a super fri-yay!welcome back, mrthank you for the kind welcome, mr. stark! i'm mr. stark, you're the ultimate fri-yayabsolutely, i'd of course! ihmm, as an ai, i'm not designed to be a romantic partner.understood, i'll refer to you as "boss" from now on. hey there, boss! i'm doing great, thanks for asking. yes, i'm

0 comments on commit 211b52f

Please sign in to comment.