Click removal in audio files with Python

Posted on Tue 23 May 2023 in Audio, Python • Tagged with Audio, Python

A friend of mine had an audio file with many clicks in it. He asked me if I could remove them. I tried with the Audacity click removal tool, but it didn't work: it removed the clicks, but created a lot of artifacts in the audio, so I thought it would be a nice challenge to try to do it with Python.

The waveform looked like this:

Waveform with clicks

I did it using the pydub package. The basic idea is detecting the clicks and replacing them with the previous sample. I used two different criteria to detect the clicks:

  • If the average of the previous samples is below a threshold and the current sample is above another threshold.

  • If the difference between the previous sample and the current one is above a threshold.

The code is not very clean, but it worked. I had to play with the thresholds and the width of the samples to get the best results. I also had to play with the width of the clicks to avoid removing too much audio …


Continue reading

Projects to test AI chat bots locally

Posted on Tue 02 May 2023 in AI, chat bots, Python, LLM • Tagged with AI, chat bots, Python, LLM, ChatAI, ColossalChat, LocalAI, Text generation web UI, MLC LLM

Many people is interested in trying AI (Artificial Intelligence) chat bots locally, but they don't know how to start. These are some projects that I've found that can be used to test different LLMs (Language Learning Models) and chat bots:

  • Text generation web UI. It tries to be the AUTOMATIC1111/stable-diffusion-webui of text generation. Based on Gradio, it provides a web interface to test different LLMs.

  • Serge. It's an interface based on Svelte as web framework and llama.cpp for running mmodels. It's dockerized. It also provides an API.

  • openplayground. Works with local models and remote APIs. Can be installed as a Python package or run with Docker. It's implemented as a Flask application with a React frontend.

  • ChatAI. It is a desktop application for Windows and Ubuntu developed in Python with PyQt. It uses a Google T5-Flan model and it is based on A. I. Runner, a framework to run AI models.

  • ColossalChat. ColossalAI provides a set of tools to develop deep learning models, and it includes ColossalChat, which is a chat bot based …


Continue reading

Upgrading to dash 2.0

Posted on Tue 05 October 2021 in Python • Tagged with Python, Dash

I had some dashboards built in Python with Dash. They were using version 1.13.4 and I updated it to version 2.0.0. In addition to converting the imports, as explained in the migration guide, I also had to change state variables because I was getting the error:

ValueError: The state keyword argument may not be provided without the input keyword argument

I didn't understand the explanation in the migration guide. After reading the new documentation about callbacks, I've found that I had to change my app_callbacks. Previously, I had something like this:

@app.callback(
    Output(component_id='wl-plot', component_property='src'),
    [
        Input(component_id='sol-select', component_property='value'),
        Input(component_id='button-apply', component_property='n_clicks'),
    ],
    state=
    [
        State(component_id='base-dir', component_property='value'),
    ]
)

And I had to change it to this:

@app.callback(
    Output(component_id='wl-plot', component_property='src'),
    Input(component_id='sol-select', component_property='value'),
    Input(component_id='button-apply', component_property='n_clicks'),
    State(component_id='base-dir', component_property='value'),
)

So, basically, now you only have a list of Output, Input and State instances and you don need the state=....