ai-app-creator / README_DEV.md
Tobias Geisler
template init: simple chatbot
0a440b6
|
raw
history blame
5.43 kB

To run Gradio apps locally using Windows Subsystem for Linux (WSL) and Visual Studio Code (VSCode), follow these steps:

1. Set Up WSL

Enable WSL

  1. Windows Features Dialog:

    • Open the Windows search bar, type "features," and select Turn Windows Features on or off.
    • Scroll down and check Windows Subsystem for Linux.
    • Click OK and restart your computer.
  2. PowerShell:

    • Open PowerShell as an Administrator and run:
      Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
      
    • Restart your computer when prompted.

Install a Linux Distro

  1. Open the Microsoft Store and search for a Linux distribution (e.g., Ubuntu).
  2. Install and launch the distribution.
  3. Follow the prompts to complete the installation and create a user ID and password.

2. Set Up Visual Studio Code with WSL

Install VSCode and WSL Extension

  1. Download and install Visual Studio Code.
  2. Install the Remote - WSL extension from the VSCode marketplace.

Open a WSL Terminal in VSCode

  1. Open your WSL terminal (e.g., Ubuntu).
  2. Navigate to your project directory.
  3. Type code . to open the current directory in VSCode.

3. Install and Run Gradio in a Virtual Environment

Create a Virtual Environment

  1. In your WSL terminal, navigate to your project directory:
    cd /path/to/your/project
    
  2. Create a virtual environment:
    python3 -m venv gradio-env
    
  3. Activate the virtual environment:
    source gradio-env/bin/activate
    

Install Gradio

  1. With the virtual environment activated, install Gradio:
    pip install gradio
    

Run the App

2. Run the Gradio app:
```bash
python app.py
  1. The app will open in a browser at http://localhost:7860.

Hot Reload Mode (Optional)

For development convenience, you can use Gradio's hot reload mode:

gradio app.py

This setup allows you to develop and run Gradio apps efficiently using WSL and VSCode, leveraging the power of a Linux environment on a Windows machine[1][3][4][5].

Citations: [1] https://code.visualstudio.com/docs/remote/wsl-tutorial [2] https://learn.microsoft.com/en-us/windows/ai/toolkit/toolkit-fine-tune [3] https://www.gradio.app/guides/quickstart [4] https://code.visualstudio.com/docs/remote/wsl [5] https://www.gradio.app/guides/installing-gradio-in-a-virtual-environment

To automatically create and update a requirements.txt file for your Python application, you have several options. Here are the most effective methods:

Updating the requirements.txt

Using pipreqs (Recommended)

Pipreqs is a third-party tool that analyzes your project's imports and generates a more accurate requirements.txt file[4][8].

  1. Install pipreqs:
    pip install pipreqs
    
  2. Navigate to your project directory.
  3. Run pipreqs:
    pipreqs .
    

Pipreqs will scan your project, identify the imports, and create a requirements.txt file with only the packages your project actually uses[4][8].

TODO Automating with GitHub Actions

For projects hosted on GitHub, you can automate the process using GitHub Actions:

  1. Create a workflow file (e.g., .github/workflows/update-requirements.yml).
  2. Use an action like timmypidashev/auto-pipreqs-cpy@master to automatically generate the requirements.txt file[5].

Best Practices

  1. Use virtual environments: This ensures your requirements.txt only includes project-specific dependencies[4].
  2. Specify versions: Use == to pin exact versions for reproducibility[4].
  3. Update regularly: Keep your requirements.txt up to date as you add or remove dependencies[4].
  4. Review generated files: Always review automatically generated requirements.txt files to ensure they're accurate and complete[6].

By following these methods and best practices, you can efficiently manage your Python project's dependencies and ensure consistency across different environments.

Citations: [1] https://stackoverflow.com/questions/31684375/automatically-create-file-requirements-txt [2] https://www.mend.io/free-developer-tools/a/community/software-dependencies/how-can-i-automatically-generate-and-update-a-requirements-txt-file-from-a-pipfile-using-pipenv/ [3] https://stackoverflow.com/questions/24764549/upgrade-python-packages-from-requirements-txt-using-pip-command [4] https://www.squash.io/how-to-automatically-create-requirementstxt-in-python/ [5] https://github.com/marketplace/actions/automatic-requirements-txt-generation-for-python-projects [6] https://pynwb.readthedocs.io/en/stable/update_requirements.html [7] https://www.geeksforgeeks.org/how-to-create-requirements-txt-file-in-python/ [8] https://www.youtube.com/watch?v=0ZeoruSobc4 [9] https://www.paleblueapps.com/rockandnull/python-update-requirements-txt/ [10] https://www.scaler.com/topics/how-to-create-requirements-txt-python/ [11] https://learn.microsoft.com/en-us/visualstudio/python/managing-required-packages-with-requirements-txt?view=vs-2022 [12] https://www.jetbrains.com/help/pycharm/managing-dependencies.html [13] https://note.nkmk.me/en/python-pip-install-requirements/ [14] https://www.freecodecamp.org/news/python-requirementstxt-explained/ [15] https://learnpython.com/blog/python-requirements-file/