Norod78's picture
Update app.py
c17d658 verified
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()