File size: 2,837 Bytes
0445543
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ef8f63
c17d658
48d80a9
0445543
 
 
 
 
 
 
 
 
 
 
 
 
c17d658
0445543
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
import spaces

title = "ืžื—ื•ืœืœ ืฉื™ืจื™ื"

DESCRIPTION = """\
# ืฆืจื• ืฉื™ืจื™ื ืžื˜ื•ืคืฉื™ื 
ื”ืžื•ื“ืœ ื”ื•ื [ืคื™ื™ื ื˜ื™ื•ืŸ ืฉืœ ื’ื•ื’ืœ ื’ืืžืžื 2 - 2ื‘ืณ](https://huggingface.co/Norod78/hebrew_lyrics-gemma2_2b-unsloth-gguf)  
ื›ืชื‘ื• ืคืจื•ืžืคื˜ ื‘ืกื’ื ื•ืŸ ืดื›ืชื•ื‘ ืœื™ ื‘ื‘ืงืฉื” ืฉื™ืจ ืขืœ / ื”ืžืชืืจ / ืฉืžื“ื‘ืจ ืขืœ ____ืด
"""

article = """\
      ื”ืžื•ื“ืœ ื›ึผื•ึผื™ึทึผื™ืœ ืขืดื™ [ื“ื•ืจื•ืŸ ืื“ืœืจ](https://linktr.ee/Norod78)  
"""

#model_id = "./hebrew_lyrics-gemma2_2b"
model_id = "Norod78/hebrew_lyrics-gemma2_2b"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
    model_id,
    device_map="auto",
    torch_dtype=torch.bfloat16)

# model_id = "Norod78/hebrew_lyrics-gemma2_2b-unsloth-gguf"
# gguf_file_name = "hebrew_lyrics-gemma2_2b-unsloth.BF16.gguf"
# tokenizer = AutoTokenizer.from_pretrained(model_id, gguf_file=gguf_file_name)
# model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.bfloat16, gguf_file=gguf_file_name).to("cpu")

torch.manual_seed(1234)

@spaces.GPU
def generate_song(prompt_text = ''):
    with torch.no_grad():
        result = ""
        input_template = tokenizer.apply_chat_template([{"role": "user", "content": prompt_text}], tokenize=False, add_generation_prompt=True)
        input_ids = tokenizer(input_template, return_tensors="pt").to(model.device)
        #sample_outputs = model.generate(**input_ids, max_new_tokens=512 , repetition_penalty=1.1, temperature=0.4, top_p=0.95, top_k=40, do_sample = True)
        sample_outputs = model.generate(**input_ids, max_new_tokens=384 , repetition_penalty=1.1, temperature=0.6, top_p=0.4, top_k=40, do_sample = True)
        #sample_outputs = model.generate(**input_ids, max_new_tokens=512 , repetition_penalty=1.1, temperature=0.5, do_sample = True)
        decoded_output = tokenizer.batch_decode(sample_outputs, skip_special_tokens=True)[0]
        result = decoded_output.replace("user\n", "ืžืฉืชืžืฉ:\n").replace("model\n", "\nืžื•ื“ืœ:\n")
        return result



demo = gr.Interface(
    generate_song,    
    inputs=gr.Textbox(lines=1, label="ื‘ืงืฉื• ืฉื™ืจ", rtl=True),
    outputs=gr.Textbox(label="ื”ืคืœื˜ ืฉืœ ื”ืžื•ื“ืœ", rtl=True),
    title=title,
    description=DESCRIPTION,
    article=article,
    examples=["ืชื ื• ืœืฉืžืฉ ืœืขืœื•ืช, ืœื‘ื•ืงืจ ืœื”ืื™ืจ", "ื›ืชื•ื‘ ืœื™ ื‘ื‘ืงืฉื” ืฉื™ืจ ืขืœ ืชืคื•ื— ืื“ืžื” ืขื ื—ืจื“ื” ื—ื‘ืจืชื™ืช", "ืฉื™ืจ ื”ืžืชืืจ ืืช ื—ื™ื™ื”ื ืฉืœ ื—ื–ื™ืจื™ื ื‘ืฆื‘ืข ืกื’ื•ืœ ืขื ื›ื ืคื™ื™ื ื•ื”ื”ืจืคืชืงืื•ืช ื”ืžืขื•ืคืคื•ืช ืฉืœื”ื", "ืฉื™ืจ ืขืœ ืคืชื— ืชืงื•ื•ื”", "ืฉื™ืจ ืขืœ ื—ื“ื™ ืงืจืŸ ื•ื•ืจื•ื“ื™ื ๐Ÿฆ„"],
    allow_flagging="never",
)

demo.queue()
demo.launch()