Skip to content

Instantly share code, notes, and snippets.

View Kjdragan's full-sized avatar

Kevin Dragan Kjdragan

  • Houston
  • 11:05 (UTC -06:00)
View GitHub Profile
@Kjdragan
Kjdragan / calculations with list in Pydantic.py
Last active July 6, 2024 21:11
@Property in Pydantic models to give function properties
from pydantic import BaseModel, Field
from typing import List
class Product(BaseModel):
name: str
price: float
quantity: int
@property
def total_value(self) -> float:
@Kjdragan
Kjdragan / llm_classification_system.py
Last active July 6, 2024 22:27 — forked from daveebbelaar/llm_classification_system.py
Classification using LLMs and the Instructor library (think agentic email, message, commnet reviews)
# --------------------------------------------------------------
# Customer Support Ticket Classification System
# --------------------------------------------------------------
import instructor
from pydantic import BaseModel, Field
from openai import OpenAI
from enum import Enum
from typing import List
@Kjdragan
Kjdragan / curl.ipynb
Created July 12, 2024 14:25
How to Curl a file instead of !wget in jupyter notebook
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kjdragan
Kjdragan / image_grid.py
Created July 12, 2024 14:45
Images layout in 2x3 grid pulled from a directory
from PIL import Image
import matplotlib.pyplot as plt
import os
image_paths = []
for img_path in os.listdir("./input_images"):
image_paths.append(str(os.path.join("./input_images", img_path)))
def plot_images(image_paths):
@Kjdragan
Kjdragan / image_describer.py
Created July 12, 2024 14:48
Describe loaded images using gpt-4o
from llama_index.multi_modal_llms.openai import OpenAIMultiModal
from llama_index.core import SimpleDirectoryReader
# put your local directore here
image_documents = SimpleDirectoryReader("./input_images").load_data()
openai_mm_llm = OpenAIMultiModal(
model="gpt-4o", api_key=OPENAI_API_KEY, max_new_tokens=1500
)
@Kjdragan
Kjdragan / get_wikipedia.ipynb
Last active July 12, 2024 15:02
Get text and image data from wikipedia
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Kjdragan
Kjdragan / request_file.py
Created July 12, 2024 16:36
How to "Request" a file instead of wget
import requests
import os
url = "https://www.dropbox.com/scl/fi/mlaymdy1ni1ovyeykhhuk/tesla_2021_10k.htm?rlkey=qf9k4zn0ejrbm716j0gg7r802&dl=1"
save_path = "./mixed_wiki/tesla_2021_10k.htm"
# Ensure the directory exists
os.makedirs(os.path.dirname(save_path), exist_ok=True)
# Download the file
@Kjdragan
Kjdragan / remove_background.py
Last active July 13, 2024 03:39
Remove background from an image
from rembg import remove
input_path = 'input.png'
output_path = 'output.png'
with open(input_path, 'rb') as i:
with open(output_path, 'wb') as o:
input = i.read()
output = remove(input)
o.write(output)
@Kjdragan
Kjdragan / video_downloading.py
Last active July 13, 2024 15:41
Video Downloading
# SET CONFIG
video_url = "https://www.youtube.com/watch?v=d_qvLDhkg00"
output_video_path = "./video_data/"
output_folder = "./mixed_data/"
output_audio_path = "./mixed_data/output_audio.wav"
filepath = output_video_path + "input_vid.mp4"
Path(output_folder).mkdir(parents=True, exist_ok=True)
@Kjdragan
Kjdragan / video_processing.py
Last active July 13, 2024 16:54
Video Processing
# We need to now extract multimodal content — Images, Text(via Audio). I extracted 1 frame every 5 seconds of the video (~160 frames) using moviepy .
def video_to_images(video_path, output_folder):
"""
Convert a video to a sequence of images and save them to the output folder.
Parameters:
video_path (str): The path to the video file.
output_folder (str): The path to the folder to save the images to.