Skip to content

Instantly share code, notes, and snippets.

@smrati
smrati / xml2json.py
Created February 4, 2026 14:02
xml to json convertor
import xmltodict
import json
import os # Import os module
def read_xml_to_dict(file_path):
"""
Reads an XML file and converts it into a Python dictionary.
Args:
file_path (str): The path to the XML file.
@smrati
smrati / kg_prompt_generator.html
Created January 24, 2026 11:11
Advanced KG Prompt Generator
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Advanced KG Prompt Generator</title>
<style>
:root {
--primary: #667eea;
@smrati
smrati / ollama_faiss.py
Last active October 31, 2024 07:53
ollama embeddings + FAISS
from langchain_community.embeddings import OllamaEmbeddings
import faiss
import numpy as np
# Initialize Ollama embeddings model
embedding_model = (
OllamaEmbeddings(model="llama3.2:3b")
)
# Sample sentences
@smrati
smrati / chromaConnect.py
Created October 25, 2024 11:37
ChromaDB + Glove Embeddings : Create a text search engine
import chromadb
from loguru import logger
class ChromaHelper:
def __init__(self, host, port):
self.host = host
self.port = port
self.chroma_client = None
@smrati
smrati / globe_based_text_retrieval.py
Created October 24, 2024 17:09
Glove embeddigs text retrival
import numpy as np
import re
from sklearn.metrics.pairwise import cosine_similarity
# Load GloVe embeddings
def load_glove_embeddings(glove_file):
embeddings_index = {}
with open(glove_file, 'r', encoding='utf-8') as f:
for line in f:
@smrati
smrati / wordle_helper.py
Created January 30, 2022 08:41
wordle solver: brute force
class wordle:
def __init__(self, input_data_path):
self.input_data_path = input_data_path
def get_path(self):
print(self.input_data_path)
def get_words_by_len(self, word_length):
"""
filter words of specific length
@smrati
smrati / multiple_ssh_setting.md
Created August 9, 2020 19:08 — forked from jexchan/multiple_ssh_setting.md
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@smrati
smrati / brix.py
Created July 19, 2020 10:24 — forked from neilslater/brix.py
Keras example image regression, extract texture height param
# -*- coding: utf-8 -*-
import numpy as np
import os
import cv2
import pandas as pd
from sklearn.cross_validation import train_test_split
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Convolution2D
import numpy as np
from keras import backend as K
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Convolution2D, MaxPooling2D
from keras.preprocessing.image import ImageDataGenerator
from sklearn.metrics import classification_report, confusion_matrix
#Start
train_data_path = 'F://data//Train'
@smrati
smrati / tutorial_1.py
Created January 25, 2020 07:34
MechanicalSoup Basic Tutorial
import mechanicalsoup
user_agent_string = 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36'
browser = mechanicalsoup.StatefulBrowser(user_agent=user_agent_string, )
browser.open('https://ebootcamp.dev')
headings_list = browser.get_current_page().find_all('h3')
for heading in headings_list:
print(heading.text)