Skip to content

Creating a cross platform GUI for OpenAI's Whisper Part 2

GitHub Repository

Why use it?

The initial motivation for this repo is to have a GUI to manipulate Whisper. This is so that I can generate initial video to text files to put up transcripts on the kivyschool.com website. One good thing about this initial integration is that I can then switch models, make the GUI better, or even run this when I have no access to a terminal/cmd/powershell. Having complete control is really nice and being able to use Kivy to rapidly prototype a GUI is invaluable (this was built in 2 days discounting all the time I spent documenting it, total time was 6 days). Later on I still need to integrate multiprocessing to push blocking code onto a Python subprocess.

What can you learn from this?

In associated github repo and associated youtube playlist, you will learn:

  • How to integrate Kivy and OpenAI's Whisper automatic speech recognition system.
  • How to deal with various Poetry bugs very easily (assuming you got the setup in the PREREQUISITE SETUP video of Pyenv + python-poetry)
  • How to integrate machine learning/tensorflow Python packages with Kivy and package them with PyInstaller
  • How to create and visualize Kivy app, then easily make it.
  • How to use and manipulate Kivy's FileChooser widget on desktop.
  • How to get and set data on various Kivy widgets.
  • How to manipulate Kivy popups
  • How to manipulate filepaths with Pathlib
  • How to package a complex Kivy app with PyInstaller
  • See firsthand how to create an app from concept to completion.
  • See the app at various stages by running the various midpointX.py files

AI Transcript provided by KivyWhisper

Hello and welcome to Kivy School. This is part 2 of the Kivy Whisper GUI app. So right now we're at part 2 and let's get started. Right now we're at part 2 which is finish the Kivy GUI. So what the app should look like. This version is saved as midpoint1.py. So let's check it out. Go here. This and then midpoint1.py. So as you can see this is what our app looks like. As you can see this is what our app looks like from part 1.

There's three buttons and then our main button right here. Then now we're building the Kivy app. So we added a file chooser and the problem is that it only shows the F drive. I wanted to show all the drives. So in midpoint2a you can see all you had to do to use a file chooser is file chooser colon. I gave it an ID which is FC for file chooser and then I picked file chooser icon layout. Then we want to choose other drives right.

The first question is how do you know what drives exist? So let's go back to the PowerPoint. So here it says the psutil package from Python. It's a basic package. It has a disk partitions function. It works on Windows and Linux and hopefully Mac because I'm not tested on Mac. But it looks like this. Install psutil and then import psutil and then save it. Then import psutil and then say psutil.disk_partitions. Then you see it shows C and F drive. So it's all the drives on my machine.

Then how do I check for what devices there are? Because these are not strings. You want to check what device it is. You can just say okay get an element of this list and then say .device. It gives me C drive. If you get the element right here which is the first element because we counted 0. Then you say .device. It will say F drive. So things to do. How do you change the file choosers drive? How do you make a drop down to change the file chooser drive? In addition we still need to select the file.

But we've already used the file chooser and I've explained in part 1 we don't need to make the text file markdown compliant anymore. How do you change the file choosers drive? I saw online it says you just need to change the file chooser.path value. You can see right here it says how to use file chooser to access files outside of C drive. Just change file chooser.path value.

You can see right here file chooser.path D E, F, G. Now let's keep going. For this app what I did was I used PDB to figure out how to get to the file chooser widget by pressing the button. I said on release import PDB and set trace. You can see right here I've released it and PDB is running. As usual you check self, root, root IDs. Here I saw root is going to be the box layout.

Then the box layout IDs I see FC which is the ID I assigned to the file chooser earlier. Then I said ok but if you do root.ids file chooser.path then it tells me the path. It's F drive. Now we have the path which is F drive. We can just set the path which will be root.ids FC.path equals to C drive.

Then that will change the file chooser drive to C drive. Again check self, check args which I forgot to type here. You should always check args as well. Parent is a good one to check. Root is a good one to check.

Here it says from the button I can already reach file chooser using root.ids FC. I can modify the path as well. Again we're still trying to change the file chooser drive. Now to make a drop down widget to choose drive.

Then drop down rule number one. Never use drop down in KV. The drop down code is saved as midpoint2a.py. We can go right here. Python midpoint2a.py.

You can see right here I set the drive. There's C drive and there's D drive. It doesn't do anything right now but I have C drive and D drive available. This is midpoint2 and let's keep going. One thing I learned was drop down is the wrong widget.

We should use a KV spinner. I keep forgetting it exists. Sometimes there are widgets and you shouldn't use the basic widget. You should always use the correct widget that fits your use case. Here the KV spinner has a button and when you click the spinner it has several selections. When you select one selection the spinner picks that choice. It's really good for the use case that I have which is just to choose one drive out of the multiple drives you have.

How do you get the spinner code to work in KV? This is not required for spinner but this is required for me to get this working in KV. You have to import psutil. This is how you import it. You import psutil as psutil. This lets you import psutil in KV code. I don't want to change the name. I just want to make it as similar to Python as possible. That's how you do it. You import psutil as psutil.

Here you can see the spinner requires some values. This values is going to be a list of entries. What did I do here? I used the list comprehension. This is just a list comprehension as shown earlier. psutil.disk_partitions gets a list of drives. Do you see right here? It's a list of drives. If you call .device on an element of the psutil.disk_partitions you get the drive name.

Later on I will convert it to string. Now you have several values that are drive names for elements used in our spinner. This is the spinner code. The list comprehension explains. It's a list comprehension. It creates a list which is what the spinner widget needs for values.

Then the list comprehension syntax. Variable for variable in a list if boolean. Right now I'm just using variable for variable in list. What am I doing here? Choose drive plus variable.device for variable in psutil.disk_partitions. Here is the list. This is the main part. From the beginning the list I'm applying list comprehension to is psutil.disk_partitions.

However, the elements in that list are not strings and would not be displayed correctly in the spinner widget. I need to convert the elements in psutil.disk_partitions to a string and display that in my spinner widget. I have already shown that you can convert an element of psutil.disk_partitions to a string using .devices. If you say .device it says C. If you check the type it says it's a string.

I can display this, the .device element, as entries for the spinner. I cannot say this one, these entries because they're not strings. Variable is just a random variable name for the elements in psutil.disk_partitions. Anything I do to variable will be applied before the for keyword.

Here's an analogy. Feed creature for creature in dogs in park. Dogs in park is a list of dogs. Creature is the variable to reference elements in the list. The list of dogs in the park. Feed creature is what you want to do. As a result, you have a list of creatures that have been fed, which in this case are dogs. The result will look like this. Bear, Belle, Bella, Birdie, Bling, and Blue. You know that these are all dogs and they have been fed already.

Similarly, for every device in psutil.disk_partitions, I will modify the list to return elements of this form. Choose drive plus bear.device. It's just string concatenation. You have two separate strings and then you make one big string. You can see the list right here. Choose drive C, choose drive F, choose drive K.

This is because the list must be displayed in the spinner as a text for each option. This is the main spinner button. Then you can see choose drive C, that's an option. Choose drive F, that's an option. Choose drive K, that's an option. The spinner choices are done. Now we need to change the file chooser path and make those buttons actually work. Here I just say the drive letter is self.text.replace, choose drive.

All this does is remove the choose drive text in front. For example, choose drive right here, I added it just to display to the user. But I don't actually want to use it as a path. I just want to get the C drive directly. If you just replace it, you're just removing it. Here we go, root ID's file chooser, this is FC, which is the ID that I have given to the file chooser in the KB. .path equals drive letter.

This will set the file chooser to change drive to the chosen spinner element. This was already shown in the last part, where you can get to the file chooser from your button. In the recap, how do you change the file chooser's drive? All you need to do is say .path. We already made a not a drop down. Skip.

Next part, we did not need to use a drop down. Actually, we can just use a spinner. We did not need to use a drop down. The correct widget is a spinner. We can use a spinner to change the file chooser drive. In addition, we are already using a file chooser and I've shown we don't need this anymore. To make text file markdown compliant.

The progress here is saved as midpoint2b.py. Let's check it out. Here's the code for midpoint2b.py. It's not that crazy. Basic imports, PSutil. Here's just the code for the spinner. Here's the values list. On text, it just says, let's set the path for file chooser. You can see right here, I can choose between C drive or I can choose between D drive. I can choose C drive or I can choose D drive. It works. Now there's that. We can choose drives. We can also choose files.

Now the next thing to do is make these buttons work. That will be part three. We're going to connect Whisper AI and Kivy preparation. Thank you for watching. This has been Kivy School.

Article Error Reporting

Message @BadMetrics on the Kivy Discord.