Skip to content

Instantly share code, notes, and snippets.

View truevis's full-sized avatar
💭
Hacking existence

Eric B truevis

💭
Hacking existence
View GitHub Profile
@truevis
truevis / delete_all_vectors_in_pinecone_db.py
Last active January 2, 2024 10:19
This Python script is a clever tool for mass-deleting vectors from a Pinecone database. It first gathers all vector IDs using a mix of randomness and query responses, then bravely asks if you really want to wipe them out before proceeding with the deletion. It's like a digital vacuum cleaner with a conscience.
import numpy as np
import pinecone
PINECONE_API_KEY = "your_pinecone_api_key"
PINECONE_ENVIRONMENT = "gcp-starter"
PINECONE_INDEX_NAME = "your_index_name"
# Function to retrieve vector IDs from a query
def get_ids_from_query(index, input_vector):
results = index.query(vector=input_vector, top_k=10000, include_values=False)
@truevis
truevis / gemini_ai_text_processing_tool.py
Last active December 28, 2023 20:06
This Python script uses Google's generative AI to enhance text files. It reads a prompt, processes text files in a chosen folder using the AI model, and saves the augmented content back to markdown files. A handy tool for batch text augmentation with a sprinkle of AI magic.
import google.generativeai as genai
import tkinter as tk
from tkinter import filedialog
import os
import time
GOOGLE_API_KEY = "YOUR_API_KEY"
genai.configure(api_key=GOOGLE_API_KEY)
def generate_content_with_gemini(prompt):
@truevis
truevis / TextDiffuser.py
Last active December 15, 2023 08:57
This Python script harnesses the power of Gradio's client API to transform text prompts into images. It's designed to connect to a specific Hugging Face model, request image generation based on detailed text and parameter inputs, then neatly organize the resulting files. It's like a tidy butler for your AI-generated art, minus the white gloves.
from gradio_client import Client
import os
import shutil
# https://huggingface.co/spaces/JingyeChen22/TextDiffuser-2
destination_directory = 'd:\\downloads\\'
client = Client("https://jingyechen22-textdiffuser-2.hf.space/--replicas/snjqb/")
result = client.predict(
"-1", # str in 'guest_id' Textbox component
"<|startoftext|>poster of four players playing beach volleyball and net photorealistic <|endoftext|><|startoftext|> l36 t18 r90 b35 [M] [a] [l] [i] [b] [u] <|endoftext|> l38 t32 r87 b52 [B] [e] [a] [c] [h] <|endoftext|> l21 t51 r105 b76 [V] [o] [l] [l] [e] [y] [b] [a] [l] [l] <|endoftext|><|endoftext|>", # str in 'Prompt. You can let language model automatically identify keywords, or provide them below' Textbox component
"Malibu/Beach/Volleyball", # str in '(Optional) Keywords. Should be separated by / (e.g., keyword1/keyword2/...)' Textbox component
@truevis
truevis / Zip_folder_with_time.py
Last active April 6, 2024 03:21
Python script to automatically compress a specified folder into a ZIP file with a unique, time-stamped filename. Ideal for regular backups and archiving.
import tkinter as tk
from tkinter import filedialog, messagebox
import shutil
import datetime
import os
import json
# Constants
LAST_FOLDER_FILE = "last_folder.json"
@truevis
truevis / find_most_common_in_sublists.py
Last active December 6, 2023 08:32
This Python script is on a quixotic quest to determine subcultural supremacy within lists via majority rule. Dubbed find_most_common_in_sublists, it valiantly volunteers an inner function to assess each sublist for its most frequent resident. However, in a twist of irony that would make Socrates smile, our ostensibly open-minded algorithm exclud…
def find_most_common_in_sublists(lists):
def find_most_common(numbers):
if not numbers:
return None # Return None for empty lists
if isinstance(numbers, list) and all(isinstance(item, (int, str)) for item in numbers):
counts = {}
max_count = 0
most_common = None
for item in numbers:
counts[item] = counts.get(item, 0) + 1
@truevis
truevis / create_pommes_duchesse_profile.py
Last active December 6, 2023 07:30
Generate a 3D ridged profile resembling pommes duchesse using random heights and angles, ensuring unique, dynamic shapes in Autodesk's DesignScript
import sys
import math
import clr
import random # Import the random module
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
def create_pommes_duchesse_profile(base_radius, ridge_count, min_ridge_height, max_ridge_height, offset):
points = []
angle_step = 360.0 / (ridge_count * 2) # Two points per ridge (peak and trough)
@truevis
truevis / ClearList.py
Last active December 6, 2023 07:33
Decluttering Made Digital: A compact Python function for purging emptiness from nested lists with surgical precision.
def ClearList(primList):
result = []
for sublist in primList:
if sublist is None or sublist == "":
continue
if isinstance(sublist, list):
sublist = ClearList(sublist)
if not sublist:
continue
result.append(sublist)
@truevis
truevis / handle_falsey_elements.py
Last active December 6, 2023 08:17
Here's a Python script that's like a truth serum for list elements. It's a simple yet crafty function named replace_falsey_or_mark_non_falsey. This little wizard takes two magical ingredients: a list of elements (items) that could be anything from None to False to an empty string, and a replacement value (rep). The spell it casts? If an element …
def replace_falsey_or_mark_non_falsey(items, rep):
elementlist = []
for item in items:
if not item:
item = rep
else:
item = False
elementlist.append(item)
return elementlist
@truevis
truevis / list_select_return_dictionary.py
Last active December 6, 2023 07:53
Behold the Python maestro of Windows Forms: a multi-select dialog that lets you tick off options like a to-do list on steroids. It's got filterable options with checkboxes, 'Select All' for the decisive, 'Select None' for the skeptics, and a memory of a goldfish with its option-tracking dictionary. Perfect for when you want choices without the m…
import clr
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
from System.Windows.Forms import Form, ListView, ListViewItem, TextBox, Button, DialogResult, CheckBox, View, AnchorStyles, Label, Panel
from System.Drawing import Point, Size, Color
def multi_select_dialog(options):
frm = Form()
frm.Width = 500
frm.Height = 900
@truevis
truevis / addImageAndTextToQR.py
Last active December 6, 2023 08:21
This Python script is a digital artist for QR codes. It takes a bunch of images from an input folder, and like a modern-day Picasso, it adds a logo and some text onto each one. The process? Open an image, slap on a logo at a specific spot, then play with some text - font, size, alignment, the whole shebang. The result? A collection of jazzed-up …
import clr
clr.AddReference('RevitNodes')
import System
clr.AddReference('System.Drawing')
from System.Drawing import Bitmap,Graphics,Font,Brushes,RectangleF
from System.Drawing.Drawing2D import SmoothingMode,InterpolationMode,PixelOffsetMode
input_folder=IN[0]
input_len=len(input_folder)+1
output_folder=IN[1]