Norod78 commited on
Commit
0445543
ยท
verified ยท
1 Parent(s): d967fe5

hebrew_lyrics_generator-gemma2_2b

Browse files
Files changed (2) hide show
  1. app.py +58 -0
  2. requirements.txt +7 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoTokenizer, AutoModelForCausalLM
4
+ import spaces
5
+
6
+ title = "ืžื—ื•ืœืœ ืฉื™ืจื™ื"
7
+
8
+ DESCRIPTION = """\
9
+ # ืฆืจื• ืฉื™ืจื™ื ืžื˜ื•ืคืฉื™ื
10
+ ื”ืžื•ื“ืœ ื”ื•ื [ืคื™ื™ื ื˜ื™ื•ืŸ ืฉืœ ื’ื•ื’ืœ ื’ืืžืžื 2 - 2ื‘ืณ](https://huggingface.co/Norod78/hebrew_lyrics-gemma2_2b-unsloth-gguf)
11
+ ื›ืชื‘ื• ืคืจื•ืžืคื˜ ื‘ืกื’ื ื•ืŸ ืดื›ืชื•ื‘ ืœื™ ื‘ื‘ืงืฉื” ืฉื™ืจ ืขืœ / ื”ืžืชืืจ / ืฉืžื“ื‘ืจ ืขืœ ____ืด
12
+ """
13
+
14
+ article = """\
15
+ ื”ืžื•ื“ืœ ื›ึผื•ึผื™ึทึผื™ืœ ืขืดื™ [ื“ื•ืจื•ืŸ ืื“ืœืจ](https://linktr.ee/Norod78)
16
+ """
17
+
18
+ #model_id = "./hebrew_lyrics-gemma2_2b"
19
+ model_id = "Norod78/hebrew_lyrics-gemma2_2b"
20
+ tokenizer = AutoTokenizer.from_pretrained(model_id)
21
+ model = AutoModelForCausalLM.from_pretrained(
22
+ model_id,
23
+ device_map="auto",
24
+ torch_dtype=torch.bfloat16)
25
+
26
+ # model_id = "Norod78/hebrew_lyrics-gemma2_2b-unsloth-gguf"
27
+ # gguf_file_name = "hebrew_lyrics-gemma2_2b-unsloth.BF16.gguf"
28
+ # tokenizer = AutoTokenizer.from_pretrained(model_id, gguf_file=gguf_file_name)
29
+ # model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, gguf_file=gguf_file_name).to("cpu")
30
+
31
+ torch.manual_seed(1234)
32
+
33
+ @spaces.GPU
34
+ def generate_song(prompt_text = ''):
35
+ with torch.no_grad():
36
+ result = ""
37
+ input_template = tokenizer.apply_chat_template([{"role": "user", "content": prompt_text}], tokenize=False, add_generation_prompt=True)
38
+ input_ids = tokenizer(input_template, return_tensors="pt").to(model.device)
39
+ sample_outputs = model.generate(**input_ids, max_new_tokens=256 , repetition_penalty=1.1, temperature=0.6, top_p=0.4, top_k=40, do_sample = True)
40
+ decoded_output = tokenizer.batch_decode(sample_outputs, skip_special_tokens=True)[0]
41
+ result = decoded_output.replace("user\n", "ืžืฉืชืžืฉ:\n").replace("model\n", "\nืžื•ื“ืœ:\n")
42
+ return result
43
+
44
+
45
+
46
+ demo = gr.Interface(
47
+ generate_song,
48
+ inputs=gr.Textbox(lines=1, label="ื‘ืงืฉื• ืฉื™ืจ", rtl=True),
49
+ outputs=gr.Textbox(label="ื”ืคืœื˜ ืฉืœ ื”ืžื•ื“ืœ", rtl=True),
50
+ title=title,
51
+ description=DESCRIPTION,
52
+ article=article,
53
+ examples=["ืชื ื• ืœืฉืžืฉ ืœืขืœื•ืช, ืœื‘ื•ืงืจ ืœื”ืื™ืจ", "ื›ืชื•ื‘ ืœื™ ื‘ื‘ืงืฉื” ืฉื™ืจ ืขืœ ืชืคื•ื— ืื“ืžื” ืขื ื—ืจื“ื” ื—ื‘ืจืชื™ืช", "ืฉื™ืจ ื”ืžืชืืจ ืืช ื—ื™ื™ื”ื ืฉืœ ื—ื–ื™ืจื™ื ืกื’ื•ืœื™ื ืขื ื›ื ืคื™ื™ื ื•ื”ื”ืจืคืชืงืื•ืช ื”ืžืขื•ืคืคื•ืช ืฉืœื”ื", "ืฉื™ืจ ืขืœ ืคืชื— ืชืงื•ื•ื”"],
54
+ allow_flagging="never",
55
+ )
56
+
57
+ demo.queue()
58
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio
2
+ accelerate
3
+ torch
4
+ transformers
5
+ tokenizers
6
+ spaces
7
+ numpy