Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -14,10 +14,16 @@ MAX_INPUT_TOKEN_LENGTH = int(os.getenv("MAX_INPUT_TOKEN_LENGTH", "4096"))
|
|
14 |
|
15 |
#Transformers Code
|
16 |
if torch.cuda.is_available():
|
17 |
-
model_id = "Qwen/Qwen2.5-7B-Instruct"
|
18 |
#model_id = "BenBranyon/sumbot7b-augmented"
|
19 |
-
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
20 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True, model_max_length=MAX_INPUT_TOKEN_LENGTH, padding="longest", language="en")
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
#Transformers Code
|
23 |
@spaces.GPU
|
@@ -38,7 +44,8 @@ def generate(
|
|
38 |
conversation.append({"role": "system", "content": system_prompt})
|
39 |
#for user, assistant in chat_history:
|
40 |
# conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
41 |
-
conversation.append({"role": "user", "content": "Channel the cosmic voice of Longshadow to craft rap lyrics
|
|
|
42 |
input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
|
43 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
44 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
@@ -53,7 +60,7 @@ def generate(
|
|
53 |
do_sample=True,
|
54 |
top_p=1.0,
|
55 |
top_k=50,
|
56 |
-
temperature=0.
|
57 |
num_beams=1,
|
58 |
repetition_penalty=1.1,
|
59 |
)
|
|
|
14 |
|
15 |
#Transformers Code
|
16 |
if torch.cuda.is_available():
|
17 |
+
#model_id = "Qwen/Qwen2.5-7B-Instruct"
|
18 |
#model_id = "BenBranyon/sumbot7b-augmented"
|
19 |
+
#model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
|
20 |
+
#tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=True, model_max_length=MAX_INPUT_TOKEN_LENGTH, padding="longest", language="en")
|
21 |
+
model_id = "BenBranyon/lora_sumbot_v2"
|
22 |
+
model = AutoPeftModelForCausalLM.from_pretrained(
|
23 |
+
model_id, # YOUR MODEL YOU USED FOR TRAINING
|
24 |
+
load_in_4bit = True,
|
25 |
+
)
|
26 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, model_max_length=MAX_INPUT_TOKEN_LENGTH, langauge="en")
|
27 |
|
28 |
#Transformers Code
|
29 |
@spaces.GPU
|
|
|
44 |
conversation.append({"role": "system", "content": system_prompt})
|
45 |
#for user, assistant in chat_history:
|
46 |
# conversation.extend([{"role": "user", "content": user}, {"role": "assistant", "content": assistant}])
|
47 |
+
conversation.append({"role": "user", "content": "Channel the cosmic voice of Longshadow to craft rap lyrics into a song. Use vivid imagery of the topic to create the song. The tone should balance sharp wit, evocative imagery, and deep insights. All output must be exclusively in English. Favor originality and inventive rhymes and deliver each verse as a work of art. Use a mix of ABAB, and AABB rhyme patterns to create a flowing, rhythmic style. Include some internal rhymes, slant rhymes, near rhymes, and perfect rhymes to add complexity. Each line should be 8-12 syllables long. The generated song should include the following song structure [INTRO] [VERSE 1] [HOOK] [VERSE 2] [OUTRO]. The topic is: " + message})
|
48 |
+
#conversation.append({"role": "user", "content": "Channel the cosmic voice of Longshadow to craft rap lyrics that blend mysticism, grit, and cultural critique. Draw on ancestral wisdom, surreal imagery, and cosmic energy to create a verse that critiques systemic oppression, inspires resilience, and celebrates liberation. The tone should balance sharp wit, evocative imagery, and spiritual insight, culminating in a coherent and impactful thought. All output must be exclusively in English, without inclusion of other languages or scripts. Favor originality and inventive rhymes and deliver each verse as a work of art. Use a mix of ABAB, AABB rhyme schemes, and internal rhymes to create a flowing, rhythmic style. Include some slant rhymes, near rhymes, and perfect rhymes to add complexity. Each line should be 8-12 syllables long. The topic is: " + message})
|
49 |
input_ids = tokenizer.apply_chat_template(conversation, return_tensors="pt")
|
50 |
if input_ids.shape[1] > MAX_INPUT_TOKEN_LENGTH:
|
51 |
input_ids = input_ids[:, -MAX_INPUT_TOKEN_LENGTH:]
|
|
|
60 |
do_sample=True,
|
61 |
top_p=1.0,
|
62 |
top_k=50,
|
63 |
+
temperature=0.8,
|
64 |
num_beams=1,
|
65 |
repetition_penalty=1.1,
|
66 |
)
|