JoannaKOKO commited on
Commit
7c28d34
·
verified ·
1 Parent(s): 3b724fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -7
app.py CHANGED
@@ -35,9 +35,8 @@ def load_image_model():
35
 
36
  # Load text model on CPU
37
  def load_text_model():
38
- base_model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b")
39
- model = PeftModel.from_pretrained(base_model, "soonbob/gemma-2-2b-tarot")
40
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
41
  return model, tokenizer
42
 
43
  # Generate card description with ZeroGPU
@@ -92,11 +91,24 @@ Provide a professional interpretation covering:
92
  - Combined message and symbolism
93
  - Practical advice
94
  - Potential outcomes"""
95
- input_ids = tokenizer(prompt, return_tensors="pt").to("cuda")
96
- outputs = model.generate(**input_ids, max_new_tokens=500)
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  # Move output to CPU before decoding
98
- interpretation = tokenizer.decode(outputs[0].cpu(), skip_special_tokens=True)
99
- return interpretation
100
 
101
  def main():
102
  """
 
35
 
36
  # Load text model on CPU
37
  def load_text_model():
38
+ tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen2.5-3B-Instruct")
39
+ model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-3B-Instruct")
 
40
  return model, tokenizer
41
 
42
  # Generate card description with ZeroGPU
 
91
  - Combined message and symbolism
92
  - Practical advice
93
  - Potential outcomes"""
94
+
95
+ messages = [
96
+ {"role": "system", "content": "You are a Tarot Card Explainer provideing relevant suggestions based on tarot card name"},
97
+ {"role": "user", "content": prompt}
98
+ ]
99
+
100
+ text = tokenizer.apply_chat_template(
101
+ messages,
102
+ tokenize=False,
103
+ add_generation_prompt=True
104
+ )
105
+ model_inputs = tokenizer([text], return_tensors="pt").to("cuda")
106
+ generated_ids = model.generate(**model_inputs, max_new_tokens=512)
107
+ generated_ids = [output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)]
108
+
109
  # Move output to CPU before decoding
110
+ response = tokenizer.batch_decode(generated_ids.cpu(), skip_special_tokens=True)[0]
111
+ return response
112
 
113
  def main():
114
  """