--- base_model: google/gemma-3-4b-it library_name: peft tags: - base_model:adapter:google/gemma-3-4b-it - lora - transformers --- # Prompt Enhancer Gemma LoRA This model enhances and expands short prompts into long, detailed prompts using a LoRA-adapted Gemma LLM. ## Installation ```bash pip install torch transformers peft ``` ## USAGE ## Usage Example ```python from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline from peft import PeftModel import torch # ----------------------------- # Load base model and LoRA # ----------------------------- base_model_name = "google/gemma-3-4b-it" # base Gemma model lora_repo = "rahul7star/gemma-3-270m-ccebc0" # trained LoRA repo # Load base model base_model = AutoModelForCausalLM.from_pretrained(base_model_name, torch_dtype=torch.float32) tokenizer = AutoTokenizer.from_pretrained(base_model_name) # Load LoRA and merge lora_model = PeftModel.from_pretrained(base_model, lora_repo, torch_dtype=torch.float32, device_map={"": "cpu"}) merged_model = lora_model.merge_and_unload() merged_model.eval() # ----------------------------- # Setup pipeline # ----------------------------- pipe = pipeline("text-generation", model=merged_model, tokenizer=tokenizer, device=-1) # CPU # ----------------------------- # Build prompt # ----------------------------- messages = [ {"role": "system", "content": "Enhance and expand the following prompt with more details and context:"}, {"role": "user", "content": "a cat sitting on a chair"} ] prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) # ----------------------------- # Generate output # ----------------------------- output = pipe(prompt, max_new_tokens=256, do_sample=True, top_p=0.95, top_k=50) print(output[0]['generated_text']) ``` ## Example ``` INPUT: a girl in rain FINE-TUNED OUTPUT: a girl is walking rain with emotions on her face A young woman stands in a rainstorm, her expression conveying a complex mix of emotions—perhaps sadness, longing, or a quiet resilience. The rain is heavy and sheets down, blurring the background and emphasizing the isolation of her form. The lighting is diffused, creating a somber and melancholic atmosphere.Texture is key to conveying emotion here. Rain streaks down her face and clothes, reflecting the light and adding to the feeling of being overwhelmed. Her hair is plastered to her face, and her posture suggests both vulnerability and strength. The composition could focus on her eyes—are they filled with tears, or a distant gaze? Her mouth might be slightly downturned, or held in a determined line. Small details like the way she holds her arms or the angle of her head can add layers of meaning to her expression. This image evokes a powerful sense of vulnerability and introspection, inviting the viewer to empathize with her experience. ``` ### Framework versions - PEFT 0.17.1