Skip to content

Instantly share code, notes, and snippets.

View jdwebprogrammer's full-sized avatar

JD Web Programmer jdwebprogrammer

View GitHub Profile
@jdwebprogrammer
jdwebprogrammer / gist:0f644a56ab2342db8c42c556ad495867
Created September 18, 2023 19:32
Python - Convert HTML to JSON
import json
from bs4 import BeautifulSoup
def html_to_json(html_file, output_file):
with open(html_file, 'r') as f:
soup = BeautifulSoup(f, 'lxml')
data = {}
for tag in soup.find_all():
if not tag.name in data:
import tempfile
import gradio as gr
from neon_tts_plugin_coqui import CoquiTTS
LANGUAGES = list(CoquiTTS.langs.keys())
coquiTTS = CoquiTTS()
def tts(text: str, language: str):
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
coquiTTS.get_tts(text, fp, speaker = {"language" : language})
@jdwebprogrammer
jdwebprogrammer / gist:fd400dc821b19e4b3734e88223dce25a
Created September 25, 2023 12:00
Basic TTS using Neon_tts_plugin_coqui
import tempfile
from neon_tts_plugin_coqui import CoquiTTS
LANGUAGES = list(CoquiTTS.langs.keys())
coquiTTS = CoquiTTS()
def tts(text: str):
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
coquiTTS.get_tts(text, fp, speaker = {"language" : "en"})
return fp.name
@jdwebprogrammer
jdwebprogrammer / gist:910e30fb50d671988f1fa2ff9258b5ab
Created October 2, 2023 02:30
Unsupervised ML - Clustering
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
# Generate synthetic data for clustering
data, _ = make_blobs(n_samples=300, centers=4, random_state=42)
# Create a K-Means clustering model
kmeans = KMeans(n_clusters=4, random_state=0)
@jdwebprogrammer
jdwebprogrammer / gist:8a660af3c5767bdc6cc69622e0f160e1
Created October 2, 2023 02:33
Unsupervised ML - Clustering Class
import numpy as np
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn.datasets import make_blobs
class KMeansClustering:
def __init__(self, n_clusters=3, random_state=0):
"""
Initialize the KMeansClustering instance.
@jdwebprogrammer
jdwebprogrammer / gist:4d7d2f875d3201a819b06bb88e0a5568
Created October 2, 2023 02:37
Unsupervised ML - Dimensionality Reduction
import numpy as np
import matplotlib.pyplot as plt
from sklearn.decomposition import PCA
class DimensionalityReductionPCA:
def __init__(self, n_components=None):
"""
Initialize the DimensionalityReductionPCA instance.
Parameters:
@jdwebprogrammer
jdwebprogrammer / gist:db6de45097e999c2335f7600856d21a7
Created October 2, 2023 02:37
Unsupervised ML - Anomaly Detection
import numpy as np
import matplotlib.pyplot as plt
from sklearn.ensemble import IsolationForest
class AnomalyDetectionIsolationForest:
def __init__(self, contamination=0.05, random_state=None):
"""
Initialize the AnomalyDetectionIsolationForest instance.
Parameters:
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.layers import Dense
from tensorflow.keras.models import Sequential
class SimpleGAN:
def __init__(self, input_dim, generator_output_dim, discriminator_output_dim):
self.input_dim = input_dim
self.generator_output_dim = generator_output_dim
@jdwebprogrammer
jdwebprogrammer / gist:c0a2773f3ad7e38e01c8e03fe9dfdbf5
Created October 2, 2023 02:41
Unsupervised ML - VAEs (Variational Autoencoders)
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.layers import Input, Dense, Lambda
from tensorflow.keras.models import Model
from tensorflow.keras.losses import mse
from tensorflow.keras import backend as K
class SimpleVAE:
def __init__(self, input_dim, latent_dim):
@jdwebprogrammer
jdwebprogrammer / gist:8dcdab14b3498d364b4725542ff39df1
Created October 2, 2023 02:44
Unsupervised ML - Topic Modeling LDA (Latent Dirichlet Allocation) Class
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import LatentDirichletAllocation
class LDATopicModel:
def __init__(self, n_topics=5, max_features=1000):
self.n_topics = n_topics
self.max_features = max_features
self.vectorizer = CountVectorizer(max_features=self.max_features, stop_words='english')