Skip to content

A generative AI project for creating realistic and stylized human portraits using Stable Diffusion and Hugging Face Diffusers.

Notifications You must be signed in to change notification settings

inesruizblach/PersonaGen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

title colorFrom colorTo sdk sdk_version app_file pinned
PersonaGen
blue
green
gradio
5.44.1
app.py
true

PersonaGen – AI-Generated Portraits with Stable Diffusion

Python License Hugging Face Demo


📌 Overview

PersonaGen is a generative AI project that creates synthetic human portraits using Stable Diffusion and the 🤗 Hugging Face Diffusers library.

The system takes a text prompt as input and produces high-quality faces that can be customised by age, gender, expression, and artistic style.

👉 Try the live demo on Hugging Face Spaces: PersonaGen Demo


🎯 Features

  • Generate photorealistic or stylised portraits from text prompts
  • Control over age, gender, mood, and style
  • Artistic filters: watercolour, comic, cyberpunk, oil painting
  • Deployed with Gradio on Hugging Face Spaces

🛠️ Tech Stack

  • Python 3.10+ – primary language for AI development and web app.
  • PyTorch – tensor computations, model execution on CPU/GPU. (pytorch.org)
  • Hugging Face Diffusers – Stable Diffusion pipelines, model management, inference. (github.com/huggingface/diffusers)
  • Gradio – easy-to-use UI for running ML models in a web browser. (gradio.app)
  • PEFT (Parameter-Efficient Fine-Tuning) – apply LoRA weights to enhance models with minimal compute. (huggingface.co/docs/peft)
  • LoRA Weights for Stable Diffusion – optional fine-tuning for realistic facial features.
  • Additional Python Libraries:
    • numpy – numerical operations.
    • Pillow – image creation and manipulation.
    • torchvision – image preprocessing and utilities.
    • ipywidgets – interactive notebook controls (optional for demos).

🗂️ Repository Structure

PersonaGen/
├── app.py                  # Gradio interface (main entry point)
├── requirements.txt        # Dependencies for Hugging Face Space
├── README.md               # Project documentation
├── .gitignore
├── examples/               # Pre-generated demo portraits
│   ├── woman_blonde.png
│   ├── smiling_kid.png
    └── young_male.png

⚡ Quick Start

Follow these steps to run PersonaGen locally or on Hugging Face Spaces:

  1. Clone the repository
git clone https://github.com/yourusername/PersonaGen.git
cd PersonaGen
  1. Install dependencies
pip install -r requirements.txt
  1. Run the app
python app.py
  1. Open the app in your browser
  • Visit the local URL shown in the console (usually http://127.0.0.1:7860).

  • Or use the Share link provided by Gradio to access the app remotely.

  1. Optional: Enable LoRA for enhanced faces
  • Install PEFT if not already installed:
pip install peft
  • Check the "Apply Face LoRA" box in the interface to use the LoRA weights.

🚀 Installation

Clone the repository and install dependencies:

git clone https://github.com/yourusername/PersonaGen.git
cd PersonaGen
pip install -r requirements.txt

Or using conda:

conda create -n personagen python=3.10 -y
conda activate personagen
pip install -r requirements.txt

Run the Gradio app locally:

python app.py

Using LoRA (optional)

Ensure the peft library is installed (pip install peft). Enable the "Apply Face LoRA" checkbox in the app for enhanced facial features.


🎨 Usage

  1. Launch the app with:
python app.py
  1. Enter a text prompt in the Gradio interface. Example prompts:
  • Modern portrait of woman with blonde hair, smiling, realistic
  • Stylised portrait of a young boy smiling, beach background, watercolor style
  • Portrait of a young male character, smiling, vibrant colours
  1. Adjust settings:
  • Steps: number of diffusion steps (default: 25)
  • Style: choose from photorealistic, watercolor, comic, cyberpunk, oil painting
  • LoRA: check the box to enhance facial features (requires peft)
  1. Generated images are displayed in the web UI and can be downloaded by clicking the image download icon.

🖼️ Example Portraits

Prompt Result with LoRA Result without LoRA
Modern portrait of woman with blonde hair, smiling, realistic
Stylised portrait of a young boy smiling, beach background, watercolor

Caption: Images in the "Result with LoRA" column include LoRA fine-tuning for enhanced facial details, while "Result without LoRA" shows the base Stable Diffusion output.

Notes:

  • Steps = number of diffusion steps (default: 25).
  • CPU runtime varies depending on hardware (around 451.4s).
  • LoRA enhancement requires peft and is optional.

This version is compact, public-repo friendly, and highlights LoRA, CPU optimization, and basic usage instructions.


🧩 References (Models & Weights)

Releases

No releases published

Packages

No packages published

Languages