Views
No views yet
pip install torch transformers peft1from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
2from peft import PeftModel
3import torch
4
5# -----------------------------
6# Load base model and LoRA
7# -----------------------------
8base_model_name = "google/gemma-3-4b-it" # base Gemma model
9lora_repo = "rahul7star/gemma-3-270m-ccebc0" # trained LoRA repo
10
11# Load base model
12base_model = AutoModelForCausalLM.from_pretrained(base_model_name, torch_dtype=torch.float32)
13tokenizer = AutoTokenizer.from_pretrained(base_model_name)
14
15# Load LoRA and merge
16lora_model = PeftModel.from_pretrained(base_model, lora_repo, torch_dtype=torch.float32, device_map={"": "cpu"})
17merged_model = lora_model.merge_and_unload()
18merged_model.eval()
19
20# -----------------------------
21# Setup pipeline
22# -----------------------------
23pipe = pipeline("text-generation", model=merged_model, tokenizer=tokenizer, device=-1) # CPU
24
25# -----------------------------
26# Build prompt
27# -----------------------------
28messages = [
29 {"role": "system", "content": "Enhance and expand the following prompt with more details and context:"},
30 {"role": "user", "content": "a cat sitting on a chair"}
31]
32
33prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
34
35# -----------------------------
36# Generate output
37# -----------------------------
38output = pipe(prompt, max_new_tokens=256, do_sample=True, top_p=0.95, top_k=50)
39print(output[0]['generated_text'])
40
41INPUT: 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.