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
26 changes: 0 additions & 26 deletions README.md

This file was deleted.

1 change: 1 addition & 0 deletions THOSE_IT_GUYS/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PWD = "/home/ikshan/ikshan/SEBI"
7 changes: 7 additions & 0 deletions THOSE_IT_GUYS/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
env
Utilities/translate/a.bin
Utilities/Wav_To_Text/__pycache__/
Utilities/Yt_To_Wav/__pycache__/
Utilities/Embeddings_Generate/__pycache__
Pipeline/__pycache__/
output.wav
51 changes: 51 additions & 0 deletions THOSE_IT_GUYS/Inf.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Serial Number,Indian Name
1,Aarav Sharma
2,Priya Patel
3,Arjun Singh
4,Aanya Gupta
5,Rohan Mehta
6,Naina Verma
7,Krish Kapoor
8,Riya Khanna
9,Advait Mishra
10,Anika Joshi
11,Kabir Kumar
12,Ishita Choudhary
13,Dev Patel
14,Zara Khan
15,Vihaan Sharma
16,Aisha Reddy
17,Aarush Bansal
18,Anaya Gupta
19,Arnav Kapoor
20,Sara Verma
21,Advik Patel
22,Diya Singh
23,Vivaan Sharma
24,Kavya Yadav
25,Aaradhya Kumar
26,Yuvan Joshi
27,Anvi Kapoor
28,Aryan Khanna
29,Kiaan Mishra
30,Ananya Agarwal
31,Rehan Patel
32,Aadhya Gupta
33,Arusha Kapoor
34,Pranav Verma
35,Inaya Reddy
36,Ayaan Bansal
37,Alisha Gupta
38,Vihan Joshi
39,Ishika Yadav
40,Samaira Kumar
41,Kian Khanna
42,Myra Choudhary
43,Advay Verma
44,Aarohi Sharma
45,Aariz Khan
46,Avani Patel
47,Aayush Singh
48,Aarna Verma
49,Vansh Kapoor
50,Kiara Joshi
32 changes: 32 additions & 0 deletions THOSE_IT_GUYS/Pipeline/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from sklearn.pipeline import Pipeline
import pandas as pd

import sys
import os

# Add the parent directory to the module search path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

from Utilities.Wav_To_Text.wav_to_text import Wav_To_Text
from Utilities.Yt_To_Wav.yt_to_wav import Yt_To_Wav
from Utilities.Embeddings_Generate.main import Embeddings
from Utilities.Fin_Advise.main import Fin_Advise

def trigger_pipeline(url):
pipeline = Pipeline([
('Generate .wav', Yt_To_Wav(url=url)),
('Generate Text', Wav_To_Text()),

('Generate embeddings', Embeddings("Utilities/Models/doc2vec_model")),
('Feeding Model with Infer Vectors', Fin_Advise("Utilities/Models/Fin_Advise_model.pkl"))
])

# Scrape data from the URL and tokenize it
prediction = pipeline.fit_transform(str(url))
print("AT THE END OF THE DAY I HAVE PREDICTED ->",prediction)

os.remove("output.wav")
return prediction

if __name__ == "__main__":
trigger_pipeline("https://youtu.be/3GGU2nE48mA?si=jAb6TCGiBTA6vFx3")
35 changes: 35 additions & 0 deletions THOSE_IT_GUYS/Utilities/Embeddings_Generate/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from sklearn.base import BaseEstimator, TransformerMixin
from gensim.models.doc2vec import Doc2Vec
from gensim.utils import simple_preprocess


class Embeddings(BaseEstimator, TransformerMixin):

def __init__(self,model_path = "Utilities/Models/doc2vec_model"):
self.model_path = model_path

def fit(self, X, y=None):
return self

def transform(self, X):
print("Text recieved as X=",X)

"""
Generate embeddings and return the embeddings
"""

model = Doc2Vec.load(self.model_path)
# Preprocess the new paragraph

new_paragraph_tokens = simple_preprocess(X)

# Infer embeddings for the new paragraph
new_paragraph_vector = model.infer_vector(new_paragraph_tokens)

# Now, `new_paragraph_vector` contains the embeddings for the new paragraph
print("Generated the infer vectors ")
print(new_paragraph_vector)
print("Moving to the next stage now")
return new_paragraph_vector


Binary file not shown.
Binary file not shown.
44 changes: 44 additions & 0 deletions THOSE_IT_GUYS/Utilities/Fin_Advise/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from sklearn.base import BaseEstimator, TransformerMixin
from gensim.models.doc2vec import Doc2Vec
from gensim.utils import simple_preprocess
import joblib
import numpy as np


class Fin_Advise(BaseEstimator, TransformerMixin):

def __init__(self,model_path = "Utilities/Models/Fin_Advise_model.pkl"):
self.model_path = model_path

def fit(self, X, y=None):
return self

def transform(self, X):
print("Inferred vectors recieved as ->", X)
print("Type of vectors = ", type(X))
X = np.array(X)
X = [X]

loaded_model = joblib.load(self.model_path) # Replace with the path to your saved model

predictions = loaded_model.predict(X)

print(predictions)
return predictions

if __name__ == "__main__":
# Load the saved model
loaded_model = joblib.load("Utilities/Models/Fin_Advise_model.pkl")# Replace with the path to your saved model
print(loaded_model)

# Make predictions
new_paragraph_vector = np.array([-0.36111203, -0.24920224, 0.62616724, -0.22456664, -0.06911723,
0.7089261 , 0.3706734 , -0.50296277, -0.36461082, -0.35107777,
0.13728353, 0.15671739, -0.0711432 , 1.1023189 , -0.49616072,
0.18149595, -0.18339647, 0.27106458, 0.3413246 , 0.5554006 ])
# Make predictions using the loaded model
new_paragraph_vector = [new_paragraph_vector]
predictions = loaded_model.predict(new_paragraph_vector)

# Print the predictions
print(predictions)
Binary file not shown.
Binary file not shown.
Binary file added THOSE_IT_GUYS/Utilities/Models/doc2vec_model
Binary file not shown.
25 changes: 25 additions & 0 deletions THOSE_IT_GUYS/Utilities/Wav_To_Text/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import pocketsphinx
from pocketsphinx import AudioFile

audio_file = "/home/ikshan/ikshan/SEBI/Output.wav"

# Define the configuration for CMU Sphinx
config = pocketsphinx.Decoder.default_config()
config.set_string('-hmm', 'path/to/acoustic_model')
config.set_string('-lm', 'path/to/language_model')
config.set_string('-dict', 'path/to/dictionary')

# Initialize the decoder
decoder = pocketsphinx.Decoder(config)

# Decode the audio file

with AudioFile(audio_file) as audio:
audio.listen()

# Perform ASR
result = decoder.decode(audio)
transcribed_text = result.hypothesis()

print("Transcribed Text:")
print(transcribed_text)
18 changes: 18 additions & 0 deletions THOSE_IT_GUYS/Utilities/Wav_To_Text/wav_text_fast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import librosa
import torch
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer

audio, rate = librosa.load("output.wav", sr=16000)

tokenizer = Wav2Vec2Tokenizer.from_pretrained("facebook/wav2vec2-base-960h")
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")

input_values = tokenizer(audio, return_tensors="pt").input_values

logits = model(input_values).logits

prediction = torch.argmax(logits, dim=-1)

transcription = tokenizer.batch_decode(prediction)[0]

print(transcription)
42 changes: 42 additions & 0 deletions THOSE_IT_GUYS/Utilities/Wav_To_Text/wav_to_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import speech_recognition as sr
from sklearn.base import BaseEstimator, TransformerMixin

audio_file_path = 'output.wav'
recognizer = sr.Recognizer()

class Wav_To_Text(BaseEstimator, TransformerMixin):

def __init__(self, audio_file_path = "output.wav"):
self.audio_file_path = audio_file_path
return

def fit(self, X=None, y=None):
return self

def transform(self, X=None):

with sr.AudioFile(self.audio_file_path) as source:
# Adjust for ambient noise if needed
recognizer.adjust_for_ambient_noise(source)

# Listen to the audio and perform ASR
try:
audio_data = recognizer.record(source)
# Use the Google Web Speech API for ASR
text = recognizer.recognize_google(audio_data)

print("Transcribed Text:")
print(text)\

print("Text generated now moving on to next stage")
return text
except sr.UnknownValueError:
print("Google Web Speech API could not understand the audio")
return None
except sr.RequestError as e:
print(f"Could not request results from Google Web Speech API; {e}")
return None

if __name__ == "__main__":
wav = Wav_To_Text("output.wav")
wav.transform(X=None)
50 changes: 50 additions & 0 deletions THOSE_IT_GUYS/Utilities/Yt_To_Wav/yt_to_wav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import yt_dlp
from sklearn.base import BaseEstimator, TransformerMixin
import os
import glob

class Yt_To_Wav(BaseEstimator, TransformerMixin):

def __init__(self, url="https://youtu.be/3GGU2nE48mA?si=mhiwloo0USzZD-9R"):
self.url = url

def fit(self, X, y=None):
return self

def download_from_url(self):
print("in down from url")
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'wav',
}],
}

with yt_dlp.YoutubeDL(ydl_opts) as ydl:
# info_dict = ydl.extract_info(self.url, download=True)
print(self.url)
ydl.download([self.url])
# downloaded_filename = ydl.prepare_filename(info_dict)

# Specify the absolute paths for the downloaded file and the new filename
directory = os.environ.get("PWD")
print(directory)
wav_files = glob.glob(os.path.join(directory, '*.wav'))

# Print the list of found .wav files
for wav_file in wav_files:
os.rename(wav_file, "output.wav")

return wav_files

def transform(self, X):
print("in transform")
file_name = self.download_from_url()
print("File downloaded from url now moving to next stage")
return file_name

# if __name__ == "__main__":
# yt = Yt_To_Wav("https://youtu.be/3GGU2nE48mA?si=lWhIBlzeMl19j1NW")

# yt.transform(X=None) # Pass a placeholder value for X, as it's required by the TransformerMixin convention
12 changes: 12 additions & 0 deletions THOSE_IT_GUYS/Utilities/translate/translate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from llama_cpp import Llama

llm = Llama(model_path="./a.bin")


def translate(sentence):
output = llm(f"USER: Convert '{sentence}' to english. ASSISTANT: ", max_tokens=1028, echo=True)
output = output['choices'][0]['text']
output = output[41+len(sentence):].replace('"','')
return output


Binary file added THOSE_IT_GUYS/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading