Skip to content

manugowda19/tryon

Repository files navigation

👕 Virtual Try-On Web App

A Python-based Virtual Try-On System that allows users to upload a photo of themselves and overlay clothing images using deep learning techniques. The system performs background removal, garment warping, and image synthesis using pretrained models. A Gradio interface is used for a simple and interactive web experience.


📂 Project Structure

      ```bash
      tryon/
      │
      ├── assets/                # Sample images, masks, preloaded clothes
      ├── client-side/           # Frontend (if applicable)
      ├── networks/              # Pretrained models and architecture files
      │
      ├── cloth-mask.py          # Extracts masks from clothing images
      ├── datasets.py            # Dataset utilities
      ├── network.py             # Model architectures
      ├── remove_bg.py           # Background removal using U-2-Net
      ├── run.py                 # Main entry point to run the try-on logic
      ├── setup_gradio.ipynb     # Gradio-based interface setup
      ├── setup_ngrok.ipynb      # Ngrok tunneling for localhost hosting
      ├── test.py                # Testing and visualization scripts
      ├── utils.py               # Helper functions
      ├── LICENSE
      └── README.md              # You are here 📍

⚙️ Features

    Upload your image and clothing image
    
    Automatic background removal (U-2-Net)
    
    Cloth segmentation and mask generation
    
    Model-based garment alignment and overlay
    
    Gradio interface for real-time preview
    
    Easily deployable with ngrok

🧠 Tech Stack

    Python 3.8+
    
    Gradio – for web interface
    
    OpenCV – for image operations
    
    PyTorch – for deep learning models
    
    U-2-Net – for background removal
    
    Ngrok – for tunneling localhost

✅ Prerequisites Make sure you have the following installed:

    python3 --version >= 3.8
    pip install -r requirements.txt

If requirements.txt is missing, install manually:

    pip install gradio opencv-python torch torchvision numpy matplotlib

🏃‍♂️ How to Run the Project

  1. Clone the repository

     git clone https://github.com/your-username/tryon.git
     cd tryon
    
  2. Background Removal (Optional Preprocessing) You can remove background from user image:

    python remove_bg.py --input_path ./assets/user.jpg --output_path ./assets/user_no_bg.png

    Or use it inside run.py dynamically.

  3. Generate Cloth Mask python cloth-mask.py --input ./assets/clothing.jpg --output ./assets/clothing_mask.png

  4. Run Virtual Try-On Pipeline This is the core script that takes the user image, cloth image, and generates the output.

    python run.py --user ./assets/user.jpg --cloth ./assets/clothing.jpg

    Optional flags:

       --remove-bg to auto-remove background
       
       --save-output to save results
    
  5. Start Gradio App (Recommended) Interactive UI using Gradio:

    jupyter notebook setup_gradio.ipynb

    Or convert to .py:

    python setup_gradio.py

  6. Expose App Using Ngrok (Optional) In setup_ngrok.ipynb, authenticate your ngrok account and expose the Gradio app:

    !ngrok authtoken YOUR_TOKEN 🧪 Example python run.py
    --user ./assets/sample_person.jpg
    --cloth ./assets/tshirt.png
    --remove-bg
    --save-output

               ✅ Output: output/result.png
    

📝 Notes network.py defines the deep learning architecture used for image warping and synthesis.

        datasets.py may be used for managing inputs and intermediate tensors if batching is supported.
        
        utils.py contains reusable functions (file I/O, resizing, visualization, etc.).

🚧 To-Do Add support for multiple garment layers

           Enable webcam-based input
          
           Pose estimation for dynamic try-on
          
           Add cloth recommendation system
          
           Integrate with Firebase or Hugging Face Spaces

🔗 References U-2-Net for salient object detection

      Gradio
      
      Virtual Try-On with PyTorch
      
      Ngrok

📜 License This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing Feel free to fork and submit a PR if you'd like to contribute to this project.

👨‍💻 Author Manu Gowda – @manugowda19

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published