t5-base-artgen-bidirectional / USAGE_EXAMPLES.md
Mitchins's picture
Upload folder using huggingface_hub
052244f verified

T5-Base Usage Examples

Practical examples for using the T5-base AI art prompt generator.

πŸ”„ Simple to Elaborate Examples

Basic Subjects

# Input: "cat"
# Output: "A fluffy tabby cat sitting gracefully on a windowsill, with soft sunlight streaming through lace curtains, creating gentle shadows on its fur. The cat has bright green eyes and a peaceful expression, surrounded by potted plants and books."

# Input: "dragon"  
# Output: "A majestic dragon with iridescent scales that shimmer between deep emerald and gold, soaring through dramatic storm clouds with lightning illuminating its powerful wings. The dragon's eyes glow with ancient wisdom as it guards a mystical mountain peak."

Portraits

# Input: "woman with flowers"
# Output: "Portrait of an elegant woman with flowing auburn hair adorned with wildflowers, painted in the style of Pre-Raphaelite masters. Soft natural lighting highlights her serene expression, with delicate petals scattered around her shoulders against a dreamy botanical background."

# Input: "steampunk character"
# Output: "A Victorian-era inventor wearing brass goggles and leather apron, surrounded by intricate clockwork mechanisms and steam-powered gadgets. Warm copper lighting illuminates the character's focused expression as they tinker with a elaborate mechanical contraption."

Landscapes & Scenes

# Input: "forest at sunset"
# Output: "An enchanted forest bathed in the golden hour light, with ancient oak trees whose branches form natural cathedral arches. Soft rays of sunlight filter through the canopy, illuminating floating motes of pollen and creating a magical, ethereal atmosphere."

# Input: "space station"
# Output: "A massive orbital space station with rotating habitat rings, set against the breathtaking backdrop of a nebula with swirling purple and pink gases. The station's metallic hull reflects starlight while small transport ships dock at illuminated ports."

πŸ”„ Elaborate to Simple Examples

Complex Art Prompts

# Input: "Hyperrealistic digital painting of a cyberpunk samurai warrior standing in a neon-lit Tokyo alleyway during a heavy rainstorm, with holographic advertisements reflecting in the wet pavement and steam rising from manholes, rendered in the style of Syd Mead with dramatic chiaroscuro lighting"
# Output: "Cyberpunk samurai in rainy Tokyo street"

# Input: "Ethereal fantasy portrait of an elven princess with platinum blonde hair and luminous blue eyes, wearing an intricate silver circlet embedded with sapphires, set against a backdrop of aurora borealis dancing across a crystalline ice palace, painted in the romantic style of John William Waterhouse"
# Output: "Elven princess with crown in ice palace"

Technical Descriptions

# Input: "Professional studio photograph of a vintage 1960s muscle car, shot with dramatic side lighting against a black seamless backdrop, captured with a medium format camera using shallow depth of field to emphasize the chrome details and custom paint job"
# Output: "Vintage muscle car studio photo"

# Input: "Architectural visualization of a sustainable eco-friendly house with living walls, solar panels, and rainwater collection systems, integrated harmoniously into a hillside landscape with native wildflowers and drought-resistant plants"
# Output: "Eco house on hillside"

🎯 Advanced Usage Patterns

Iterative Refinement

# Start simple
prompt = "elaborate: mountain landscape"
result1 = generate(prompt)
# "Snow-capped mountain peaks under a dramatic sky..."

# Refine further  
prompt2 = f"elaborate: {result1} with more atmospheric details"
result2 = generate(prompt2)
# Even more detailed atmospheric description

Style Transfer

# Add style information
prompt = "elaborate: cat portrait in Renaissance painting style"
# Output: "Renaissance-style oil painting of a regal cat with detailed fur texture, painted in the manner of classical masters with rich chiaroscuro lighting..."

prompt = "elaborate: robot in Art Nouveau style"  
# Output: "An ornate mechanical automaton designed with flowing Art Nouveau curves and botanical motifs..."

Mood and Atmosphere

# Emotional context
prompt = "elaborate: peaceful garden scene"
# Output: "A tranquil Japanese zen garden with carefully raked sand patterns, moss-covered stones, and a gentle water feature..."

prompt = "elaborate: dramatic storm scene"
# Output: "A powerful thunderstorm over rolling hills with jagged lightning bolts illuminating dark storm clouds..."

πŸ› οΈ API Integration Example

from transformers import T5Tokenizer, T5ForConditionalGeneration

class PromptGenerator:
    def __init__(self, model_path='./fine_tuned_t5_base'):
        self.tokenizer = T5Tokenizer.from_pretrained(model_path)
        self.model = T5ForConditionalGeneration.from_pretrained(model_path)
        
    def elaborate(self, simple_prompt, creativity=1.0):
        """Convert simple description to elaborate prompt"""
        input_text = f"Generate a detailed artistic prompt for: {simple_prompt}"
        
        inputs = self.tokenizer.encode(input_text, return_tensors='pt', max_length=512, truncation=True)
        
        outputs = self.model.generate(
            inputs,
            max_length=256,
            num_beams=4,
            temperature=creativity,
            do_sample=creativity > 1.0,
            pad_token_id=self.tokenizer.pad_token_id
        )
        
        return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
    
    def simplify(self, elaborate_prompt):
        """Extract core concept from elaborate prompt"""
        input_text = f"Simplify this prompt: {elaborate_prompt}"
        
        inputs = self.tokenizer.encode(input_text, return_tensors='pt', max_length=512, truncation=True)
        
        outputs = self.model.generate(
            inputs,
            max_length=128,
            num_beams=4,
            pad_token_id=self.tokenizer.pad_token_id
        )
        
        return self.tokenizer.decode(outputs[0], skip_special_tokens=True)

# Usage
generator = PromptGenerator()

# Elaborate
detailed = generator.elaborate("sunset over ocean")
print(detailed)

# Simplify  
core = generator.simplify("A photorealistic sunset over calm ocean waters with dramatic orange and pink clouds reflected in the gentle waves...")
print(core)

🎨 Creative Workflows

Prompt Enhancement Pipeline

  1. Start with basic concept: "cat portrait"
  2. Elaborate: "Dignified Persian cat with luxurious white fur..."
  3. Add style: "...in the style of classical oil painting"
  4. Refine mood: "...with warm, golden hour lighting"

Concept Exploration

  1. Generate multiple variations of same concept
  2. Use different creativity temperatures (0.8-1.3)
  3. Combine elements from different outputs
  4. Iterate and refine based on results

Prompt Optimization

  1. Generate elaborate prompt
  2. Test with AI art generator
  3. Simplify to extract working elements
  4. Re-elaborate with improvements
  5. Repeat until optimal

πŸ”§ Tips & Best Practices

Input Guidelines

  • Clear subjects: "cat" better than "feline creature"
  • Specific contexts: "Victorian woman" vs "old-fashioned person"
  • Avoid overly complex inputs: Model works best with 2-5 word inputs

Generation Parameters

  • Creativity=1.0: Consistent, reliable outputs
  • Creativity=1.1-1.3: More varied, creative outputs
  • Max_length=256: Good balance of detail vs coherence
  • Num_beams=4: Optimal quality/speed tradeoff

Common Issues

  • Repetition: Lower temperature or use different phrasing
  • Too generic: Add more specific context to input
  • Too elaborate: Use simplify function to extract core elements

πŸ“Š Quality Assessment

Rate generated prompts on:

  • Specificity: Clear, actionable descriptions
  • Creativity: Interesting, non-generic elements
  • Coherence: Logical, consistent details
  • Usability: Works well with AI art generators
  • Bias: Avoids oversaturated descriptors ("beautiful", etc.)