Spaces:
Running
on
Zero
Running
on
Zero
hebrew_lyrics_generator-gemma2_2b
Browse files- app.py +58 -0
- 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
|