Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request: GUI and/or mobile apps #55

Open
todoneunl opened this issue Mar 27, 2024 · 5 comments
Open

Request: GUI and/or mobile apps #55

todoneunl opened this issue Mar 27, 2024 · 5 comments

Comments

@todoneunl
Copy link

I don't know if this is the right place to ask. I think deface works very well. It would be great if a GUI and/or mobile apps (for example an Android version) with the deface engine, would be created. So people without technical knowledge or if they only have a mobile phone available, can also benefit from this great tool. Thank you for considering.

@StealUrKill
Copy link

I have created a gui but it still requires python to be installed with all the supporting extras. This works with cuda, tensor, openvino, cpu, and dml execution providers. OpenVino is harder to get going as I cant seem to make it work with the pip module and have to use the zip located https://docs.openvino.ai/2023.3/openvino_docs_install_guides_installing_openvino_from_archive_windows.html

And then specifically tell it to use the setupvars.bat that comes with the zip. Also it seems the onnxruntime for openvino 1.17.1 does not work as there is entry point errors in the capi dll but 1.16.0 works fine.

image

This is some of the code that is in place for the GUI. Now I have also forked this and added extra options to the Deface tool.

using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Management;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Collections.Generic;


namespace AnonFacesApp
{
    public partial class MainForm : Form
    {
        private Process runningProcess;
        private bool isProcessRunning;
        private string lastSelectedFile;
        private string ExecutionProvider;
        private readonly string CudaDirectory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA";
        private readonly string TensorDirectory = @"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA";
        private readonly string NvinferDllPath = "lib\\nvinfer.dll";
        private const string KeepAudioOption = "--keep-audio";
        private const string ViewPreviewOption = "--preview";
        private const string ScaleOption = "--scale 1280x720";
        private const string DistortAudio = "--distort-audio";
        private const string rootDirectory = @"C:\Program Files (x86)\Intel";
        private decimal thresh = 0.200M;
        private Process ffmpegProcess;


        public MainForm()
        {
            InitializeComponent();
            this.AllowDrop = true;
            this.Load += MainForm_Load;
            AudioCheckBox.Checked = true;
            trackBar1.Scroll += TrackBar1_Scroll;
        }


        private void MainForm_Load(object sender, EventArgs e)
        {
            // In the MainForm_Load event, set the TrackBar properties:
            trackBar1.Minimum = 0;
            trackBar1.Maximum = 12; // 10 steps (0.02, 0.04, 0.06, 0.08, 0.1, 0.12, 0.14, 0.16, 0.18, 0.20, 0.22)
            trackBar1.LargeChange = 1;
            trackBar1.SmallChange = 1;
            trackBar1.TickFrequency = 1;
            trackBar1.Value = 9; // 0.200 corresponds to the midddle step
            UpdateLabelFromTrackBarValue(); // Update the label to reflect the default value.
            List<string> availableProviders = GetAvailableProviders();
            // Populate the ComboBox with the obtained providers
            ExecutionComboBox.Items.AddRange(availableProviders.ToArray());

            // Check if OpenVINO or CUDA are available
            if (availableProviders.Contains("OpenVINOExecutionProvider"))
            {
                ExecutionComboBox.SelectedItem = "OpenVINOExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
            else if (availableProviders.Contains("CUDAExecutionProvider"))
            {
                ExecutionComboBox.SelectedItem = "CUDAExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
            else if (availableProviders.Contains("DmlExecutionProvider"))
            {
                ExecutionComboBox.SelectedItem = "DmlExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
            else
            {
                // If neither provider is available, you can set a default selection
                ExecutionComboBox.SelectedItem = "CPUExecutionProvider";
                SetExecutionProviderFromComboBox();
            }
        }

        private List<string> ParseAvailableProviders(string providersString)
        {
            List<string> availableProviders = new List<string>();

            string[] providerArray = providersString
                .Replace("[", "")
                .Replace("]", "")
                .Replace("'", "")
                .Split(',')
                .Select(provider => provider.Trim())
                .ToArray();

            availableProviders.AddRange(providerArray);

            return availableProviders;
        }

        private List<string> GetAvailableProviders()
        {
            try
            {
                System.Diagnostics.Process process = new System.Diagnostics.Process
                {
                    StartInfo = new System.Diagnostics.ProcessStartInfo
                    {
                        FileName = "python",
                        RedirectStandardOutput = true,
                        UseShellExecute = false,
                        CreateNoWindow = true,
                        Arguments = "-c \"import onnx; import onnxruntime; print(onnxruntime.get_available_providers())\""
                    }
                };

                process.Start();
                string providersString = process.StandardOutput.ReadToEnd();

                return ParseAvailableProviders(providersString);
            }
            catch (Exception)
            {
                // Handle the exception if needed
                return new List<string>();
            }
        }



        private void SetExecutionProviderFromComboBox()
        {
            int selectedProviderIndex = ExecutionComboBox.SelectedIndex;

            // Get the list of available providers dynamically
            List<string> availableProviders = GetAvailableProviders();

            if (selectedProviderIndex >= 0 && selectedProviderIndex < availableProviders.Count)
            {
                // Set the execution provider based on the selected index
                string selectedProvider = availableProviders[selectedProviderIndex];

                // Implement logic based on the selected provider
                switch (selectedProvider)
                {
                    case "DmlExecutionProvider":
                        ExecutionProvider = "--ep DmlExecutionProvider";
                        break;

                    case "CPUExecutionProvider":
                        ExecutionProvider = "--ep CPUExecutionProvider";
                        break;

                    case "CUDAExecutionProvider":
                        ExecutionProvider = "--ep CUDAExecutionProvider";
                        break;

                    case "TensorrtExecutionProvider":
                        ExecutionProvider = "--ep TensorrtExecutionProvider";
                        break;

                    case "OpenVINOExecutionProvider":
                        ExecutionProvider = "--ep OpenVINOExecutionProvider";
                        break;

                    default:
                        // Handle the default case (e.g., show an error message)
                        MessageBox.Show("Invalid selection");
                        break;
                }
            }
            else
            {
                // Handle the case where the selected index is out of bounds
                MessageBox.Show("Invalid selection");
            }
        }```



@StealUrKill
Copy link

I have created a gui but it still requires python to be installed with all the supporting extras. This works with cuda, tensor, openvino, cpu, and dml execution providers. OpenVino is harder to get going as I cant seem to make it work with the pip module and have to use the zip located https://docs.openvino.ai/2023.3/openvino_docs_install_guides_installing_openvino_from_archive_windows.html

And then specifically tell it to use the setupvars.bat that comes with the zip. Also it seems the onnxruntime for openvino 1.17.1 does not work as there is entry point errors in the capi dll but 1.16.0 works fine.

Seems like the issue with 1.17.1 was my Python Version. I thought i had 3.11.9 but the instance was confused on the multiple versions on my machine. So this works lol

@StealUrKill
Copy link

I don't know if this is the right place to ask. I think deface works very well. It would be great if a GUI and/or mobile apps (for example an Android version) with the deface engine, would be created. So people without technical knowledge or if they only have a mobile phone available, can also benefit from this great tool. Thank you for considering.

I have finally got the GUI in all python up and created. Not the prettiest but using the existing code and parsing the args to it. This uses tkinter and requires dlib for the face recognition. I also had to restructure it to make it work better for me. I am sure there is some things that I can do better and open to suggestions.

Screenshot 2024-09-06 214004

@todoneunl
Copy link
Author

@StealUrKill Looks good. Do you have this code in a repo (can't find it here)? And how to install it?

@StealUrKill
Copy link

@StealUrKill Looks good. Do you have this code in a repo (can't find it here)? And how to install it?

It's under the RC branch due to some extra things I need to finish up. I have some pre compiled dlib python whl's if you need face recognition. The whole thing has been restructured as I have been adding so much to it to keep it easier to follow for more. The only real issue I have at the moment is if you distort the audio and then hit stop it will do the whole audio for the entire clip but only have the video up to the stop. If you need any help let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants