TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #241 · 5 мај

Можно ли в Python создавать бинарные файлы? Конечно можно. Для этого в Python есть следующие инструменты: ▫️ тип данных bytes и bytearray ▫️ открытие файла в режиме wb (write binary) или rb (read binary) ▫️ модуль struct Про модуль struct поговорим в первую очередь. Файл в формате JSON или Yaml внутри себя содержит разметку данных. Всегда можно определить где список начался а где закончился. Где записана строка а где словарь. То есть формат записи данных содержит в себе элементы разметки данных. В binary-файле данные не имеют визуальной разметки. Это просто байты, записанные один за другим. Правила записи и чтения находятся вне файла. Модуль struct как раз и помогает с организацией данных в таком файле с помощью определения форматов записи для разных частей файла. Модуль struct преобразует Python-объекты в массив байт, готовый к записи в файл и имеющий определённый вид. Для этого всегда следует указывать формат преобразования (или, как оно здесь называется - запаковки). Формат нужен для того, чтобы выделить достаточное количество байт для записи конкретного типа объекта. В последствии с помощью того же формата будет производиться чтение. При этом следует помнить что мы говорим о типах языка С а не Python. Именно формат определяет, что записано в конкретном месте файла, число, строка или что-то еще. Вот какие токены формата у нас есть. Помимо этого, первым символом можно указать порядок байтов. На разных системах одни и те же типы данных могут записываться по-разному, поэтому желательно указать конкретный способ из доступных. Если этого не сделать, то используется символ '@', то есть нативный для текущей системы. В строке формата мы пишем в каком порядке и какие типы собираемся преобразовать в байты. Запакуем в байты простое число, токен "i". >>> import struct >>> struct.pack('=i', 10) b'\n\x00\x00\x00' Теперь несколько float, при этом нужно передавать элементы не массивом а последовательностью аргументов. >>> struct.pack('=fff', 1.0, 2.5, 4.1) b'\x00\x00\x80?\x00\x00 @33\x83@' Вместо нескольких токенов можно просто указать нужное количество элементов перед одним токеном, результат будет тот же. >>> struct.pack('=3f', 1.0, 2.5, 4.1) b'\x00\x00\x80?\x00\x00 @33\x83@' Теперь запакуем разные типы >>> data = struct.pack('=fiQ', 1.0, 4, 100500) я запаковал типы float, int и unsigned long long (очень большой int, на 8 байт) b'\x00\x00\x80?\x04\x00\x00...' Распаковка происходит аналогично, но нужно указать тот же формат, который использовался при запаковке. Результат возвращается всегда в виде кортежа. >>> struct.unpack('=fiQ', data) (1.0, 4, 100500) Как видите, ничего страшного! #lib#basic

Hashtags

Резултати

Пронајдени 5 слични објави

Пребарај: #mlx

当前筛选 #mlx清除筛选
GitHub Trends

@githubtrending · Post #15143 · 14.09.2025 г., 12:00

#python#llms#mlx MLX LM is a Python tool that helps you run and fine-tune large language models (LLMs) efficiently on Apple Silicon Macs. It connects easily to thousands of models on Hugging Face, supports model quantization to save memory, and allows distributed training. You can generate text or chat with models via simple commands or Python code. It also offers features like prompt caching and memory optimization for handling long texts, making it faster and less resource-heavy. This means you can run powerful AI models locally on your Mac without needing expensive cloud services, saving cost and improving speed. https://github.com/ml-explore/mlx-lm

GitHub Trends

@githubtrending · Post #14655 · 01.05.2025 г., 13:30

#typescript#electron#llama#llms#lora#mlx#rlhf#transformers Transformer Lab is a free, open-source tool that lets you easily work with large language models on your own computer, offering one-click downloads for popular models like Llama3 and Mistral, fine-tuning across different hardware (including Apple Silicon and GPUs), and features like chatting, training, and evaluating models through a simple interface—saving you from complex setups like CUDA or Python version issues[1][2][5]. https://github.com/transformerlab/transformerlab-app

GitHub Trends

@githubtrending · Post #15614 · 13.04.2026 г., 11:30

#typescript#ai#cuda#mlx#qwen3_tts#qwen3_tts_ui#voice_ai#voice_clone#whisper Voicebox is a free, open-source voice synthesis studio that lets you clone voices, generate speech in 23 languages, and apply audio effects—all running privately on your computer. You can create realistic voice clones from just seconds of audio, use five different text-to-speech engines for different needs, add effects like reverb and pitch shift, and build multi-voice projects with a timeline editor. The key benefit is complete privacy: your voice data and AI models never leave your machine, unlike cloud-based alternatives. It also includes an API for building voice-powered applications and works across Mac, Windows, and Linux with GPU acceleration support. https://github.com/jamiepine/voicebox

GitHub Trends

@githubtrending · Post #14684 · 08.05.2025 г., 12:00

#python#apple_silicon#audio_processing#mlx#multimodal#speech_recognition#speech_synthesis#speech_to_text#text_to_speech#transformers MLX-Audio is a powerful tool for converting text into speech and speech into new audio. It works well on Apple Silicon devices, like M-series chips, making it fast and efficient. You can choose from different languages and voices, and even adjust how fast the speech is. It also includes a web interface where you can see audio in 3D and play your own files. This tool is helpful for making audiobooks, interactive media, and personal projects because it's easy to use and provides high-quality audio quickly. https://github.com/Blaizzy/mlx-audio

GitHub Trends

@githubtrending · Post #15600 · 04.04.2026 г., 11:30

#python#apple_silicon#florence2#idefics#llava#llm#local_ai#mlx#molmo#paligemma#pixtral#vision_framework#vision_language_model#vision_transformer MLX-VLM lets you run, chat with, and fine-tune Vision Language Models (VLMs) plus audio/video models on your Mac using MLX—install easily with `pip install -U mlx-vlm`. Use CLI for quick text/image/audio generation (e.g., `mlx_vlm.generate --model ... --image photo.jpg`), Gradio UI for chats, Python scripts, or a FastAPI server with OpenAI-compatible endpoints supporting multi-images/videos. Features like TurboQuant cut KV cache memory by 76%, and LoRA/QLoRA fine-tuning works on consumer hardware. You benefit by experimenting with powerful multimodal AI locally—fast, memory-efficient, no cloud costs, perfect for Mac users tweaking models affordably. https://github.com/Blaizzy/mlx-vlm