This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pydantic import BaseModel, Field | |
| from typing import List | |
| class Product(BaseModel): | |
| name: str | |
| price: float | |
| quantity: int | |
| @property | |
| def total_value(self) -> float: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -------------------------------------------------------------- | |
| # Customer Support Ticket Classification System | |
| # -------------------------------------------------------------- | |
| import instructor | |
| from pydantic import BaseModel, Field | |
| from openai import OpenAI | |
| from enum import Enum | |
| from typing import List |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| ) | |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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. | |
OlderNewer