Giter Site home page Giter Site logo

llmscripts's Introduction

What does this do?

llm-utility.py queries a koboldcpp API running an LLM and asks it for information on files. It starts in a directory specified by the user and finds any files in request caegories. If the --recursive flag is added it will crawl through all directories inside the specified as well.

Documents:

It will attempt to parse any documents (txt, pdf, doc, etc) and it will send the content to the LLM and query it for Title, Topic, Subject, Author, Creator, and then ask for a suggested filename.

Images:

It will send the images to the API one by one and ask the LLM to describe them. This requires a vision capable model with an mmproj file, like llava. Once the image is captioned it sends the caption to LLM as if the caption were a document and asks for a description and recommended filename.

The llm-utility.py script does not alter any files.

The other script, if you run it, will irrevocably and without questioning or confirming rename every file in the file_metadata.json created by the llm-utility to the recommended on by the LLM by using the path included. It will rename them ALL. Do not run this on anything you care about without at least reading the json to see what it will rename.

The script adds files info to the json every time you run it! If you run it at directory 1, then again at directory 2, it will add on the file info from directory 2 to directory 1 and if you run the rename script it will rename all the files in both directories**

Installation

Install spacy and requirements:

pip install -U pip setuptools wheel
pip install -U spacy
python -m spacy download en_core_web_sm
pip install -r requirements.txt

Grab latest koboldcpp from repo:

Grab the phi3 llava llm gguf and mmproj file:

Open koboldcpp executable, load phi3 and the mmproj, set options and when it is loaded type:

python llm-utility.py "c:\directory\to\crawl\with\no\ending\slash"

If you are want it to crawl through the entire directory tree add --recursive Open the file-metadata.json file in notepad++ or chrome. It will look like this:

{
  "carmack.txt": {
    "File": "carmack.txt",
    "Title": "Connect 2021: John Carmack",
    "Caption": "",
    "Creator": "John Carmack",
    "Author": "John Carmack",
    "Subject": "Virtual Reality",
    "Topic": "Presentation and Discussion of Virtual Reality Technologies and Advancements",
    "Filetype": "",
    "FullPath": "C:\\test\\carmack.txt",
    "PreviousPath": "",
    "PreviousName": "",
    "Size (KB)": 5,
    "Created": "2024-06-05T23:01:17.889296",
    "Modified": "2024-06-05T23:01:30.246009",
    "Category": "Document",
    "ProposedFilename": "connect_2021_john_carmack.mp4"
  },
  "image2.jpg": {
    "File": "image2.jpg",
    "Title": "A Man in a Purple Plaid Jacket Holding a Red Leash with a Dog on the Other End of the Leash",
    "Caption": "A man in a purple plaid jacket holding a red leash with a dog on the other end of the leash.",
    "Creator": "Anonymous",
    "Author": "Anonymous",
    "Subject": "Dogs",
    "Topic": "Pets",
    "Filetype": "",
    "FullPath": "C:\\test\\image2.jpg",
    "PreviousPath": "",
    "PreviousName": "",
    "Size (KB)": 98,
    "Created": "2024-07-08T18:47:29.460219",
    "Modified": "2024-07-08T18:47:21.701451",
    "Category": "Image",
    "ProposedFilename": "man_in_purple_jacket_and_dog.jpg"
  }

Now you can do whatever you want with that information.

But if you are feeling lucky you can have it rename all your files:

python .\file-renamer-script.py

It will then rename every document and image that it got info for and put in the file-metadata.json file. It will also update the field for PreviousName to be the previous filename. It will hopefully disregard wrong proposed extensions.

I TAKE NO RESPONSIBILITY FOR WHAT HAPPENS WHEN YOU RUN THIS

It might rename all your files to be variations of swear words or something -- the LLM is the one calling the shots and who knows what it will do. At least check the filenames are sane before running the renamer.

Why did I choose these requirements?

  • ftfy fixes unicode parsing errors that happened in the past (if a file was decoded and/or encoded wrong by some other program)
  • natsort sorts files as the OS does, so that when you look at the metadata output it is not in a strange order making you hunt for files
  • json-repir is needed because LLMs often will give you json that looks ok but doesn't parse
  • spacy is used for fast and accurate sentence chunking
  • tika is used to parse non-text files

Citations:

@misc{speer-2019-ftfy, author = {Robyn Speer}, title = {ftfy}, note = {Version 5.5}, year = 2019, howpublished = {Zenodo}, doi = {10.5281/zenodo.2591652}, url = {https://doi.org/10.5281/zenodo.2591652} }

prompt_template.json was basically taken verbatim from https://github.com/aseichter2007/ClipboardConqueror/blob/main/inferenceInterface.js and converted into json format.

llmscripts's People

Contributors

jabberjabberjabber avatar

Stargazers

 avatar syddharth avatar Gil Klein avatar Gavin Brown avatar Virgil avatar Steffen Röcker avatar Willi Kappler avatar Viraj Noorithaya avatar  avatar

Watchers

Kostas Georgiou avatar  avatar

llmscripts's Issues

'str' object has no attribute 'get'

Hi,
I tried it out in Ubuntu , and got following error.

air) Ubuntu@0136-ict-prxmx50056:~/llmscripts$ python3 llm-utility.py "/home/Ubuntu/testimages" --api-url http://localhost:5001
Processing file 1 of 1: /home/Ubuntu/testimages/4a.jpgError processing task 'metadata': unsupported operand type(s) for +: 'NoneType' and 'int'

Error processing /home/Ubuntu/testimages/4a.jpg: 'str' object has no attribute 'get'

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.