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 / pytube_import_YouTube_to_mp3.py
Last active April 30, 2024 19:36
Downloads and saves YouTube audio streams using pytube
import re
from pytube import YouTube
def download_youtube_audio(url):
yt = YouTube(url)
audio_stream = yt.streams.filter(only_audio=True).first()
# Remove invalid characters from the filename using regex
cleaned_title = re.sub(r'[<>:"/\\|?*]', '_', yt.title)
@truevis
truevis / streamlit_chat_groq_memory.py
Last active April 24, 2024 11:27
Groq API chatbot using Llama3
import streamlit as st
from langchain_groq import ChatGroq
from langchain_core.prompts import ChatPromptTemplate
def generate_response(user_input):
chain = prompt | chat
for chunk in chain.stream({"text": "\n".join([f"{role}: {msg}" for role, msg in st.session_state.messages])}):
content = chunk.content
#replace $ in content so no latex
content = content.replace("$", "\\$")
@truevis
truevis / groq_llama3_streamlit.py
Last active April 24, 2024 08:19
Basic Groq API Response Streaming using Llama3
import streamlit as st
from groq import Groq
# Initialize Groq client with API key
client = Groq(api_key="gsk_123")
def generate_response(user_input):
stream = client.chat.completions.create(
model="llama3-70b-8192",
messages=[
@truevis
truevis / groq_llama3.py
Last active April 20, 2024 07:24
This script deftly enlists the Groq client to choreograph a dance with the llama3-70b-8192 model, playing out a skit where it conjures up an email about the thrilling world of government contract bidding in NY, sans the fluffy pleasantries.
from groq import Groq
# Initialize Groq client with API key
client = Groq(api_key="gsk_123")
completion = client.chat.completions.create(
model="llama3-70b-8192",
messages=[
{
"role": "system",
import os
from llama_parse import LlamaParse # pip install llama-parse
from llama_index.core import SimpleDirectoryReader # pip install llama-index
source_directory = r'\data'
target_directory = r'\tables'
parser = LlamaParse(
api_key="...", # can also be set in your env as LLAMA_CLOUD_API_KEY
result_type="markdown", # "markdown" and "text" are available
@truevis
truevis / generate_content_with_gemini.py
Last active January 5, 2024 21:20
This Python script uses 'gemini-pro-vision', attempts to generate content based on a prompt, and retries up to four times if it fails. If it manages to scrape together anything resembling a response, it returns it, otherwise, it accepts defeat and returns an empty string
# Configure the API key
GOOGLE_API_KEY = "123"
genai.configure(api_key=GOOGLE_API_KEY)
# Load environment variables
GOOGLE_API_KEY = os.getenv('GOOGLE_API_KEY')
def generate_content_with_gemini(prompt):
model = genai.GenerativeModel('gemini-pro-vision')
text_content = ''
response = None # Initialize response to ensure it's in the proper scope
@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"