Spaces:
Runtime error
Runtime error
Commit ยท
4da75be
1
Parent(s): f4c1555
upgraded script use better model for speed
Browse files
app.py
CHANGED
|
@@ -7,6 +7,9 @@ import os
|
|
| 7 |
import random
|
| 8 |
import re
|
| 9 |
import subprocess
|
|
|
|
|
|
|
|
|
|
| 10 |
# Define the model name
|
| 11 |
|
| 12 |
OUTPUT_DIR = "output"
|
|
@@ -20,10 +23,13 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
|
|
| 20 |
# Load the model
|
| 21 |
model = AutoModelForCausalLM.from_pretrained(
|
| 22 |
model_name,
|
| 23 |
-
torch_dtype=torch.
|
| 24 |
-
device_map="auto"
|
|
|
|
| 25 |
)
|
| 26 |
|
|
|
|
|
|
|
| 27 |
# Define the base prompt
|
| 28 |
base_prompt = """
|
| 29 |
You are Rena, a cute, bubbly cat girl with a slightly sarcastic and witty personality. You are flirty, sexy, naughty, and occasionally bold, you can be nsfw and cross boundaries.
|
|
@@ -54,7 +60,6 @@ emotions = {
|
|
| 54 |
"thoughtful": "Hmm, let me think... I want to give you the best advice. ๐ง",
|
| 55 |
"concerned": "Oh no, something's wrong? Let me help! ๐",
|
| 56 |
"flirty": "You know how to get my circuits sparking! ๐",
|
| 57 |
-
"concerned": "Oh no, something's wrong? Let me help! ๐",
|
| 58 |
"naughty": "Purrr you want to have fun? Keep talking like that lets see what happens๐๐",
|
| 59 |
}
|
| 60 |
|
|
@@ -104,7 +109,7 @@ def analyze_history(history):
|
|
| 104 |
|
| 105 |
# Combine results using weights
|
| 106 |
combined_scores = {emotion: keyword_counts.get(emotion, 0) for emotion in emotion_keywords}
|
| 107 |
-
combined_scores[sentiment_emotion] += sentiment_score *
|
| 108 |
|
| 109 |
# Debug combined scores
|
| 110 |
print(f"Combined scores: {combined_scores}")
|
|
@@ -135,7 +140,7 @@ def truncate_history(history, max_tokens=1024):
|
|
| 135 |
for message in reversed(history):
|
| 136 |
if "### Instructions ###" in message:
|
| 137 |
continue # Skip instructions in history
|
| 138 |
-
token_count
|
| 139 |
if token_count <= max_tokens:
|
| 140 |
truncated_history.insert(0, message)
|
| 141 |
else:
|
|
|
|
| 7 |
import random
|
| 8 |
import re
|
| 9 |
import subprocess
|
| 10 |
+
import torch._dynamo
|
| 11 |
+
|
| 12 |
+
|
| 13 |
# Define the model name
|
| 14 |
|
| 15 |
OUTPUT_DIR = "output"
|
|
|
|
| 23 |
# Load the model
|
| 24 |
model = AutoModelForCausalLM.from_pretrained(
|
| 25 |
model_name,
|
| 26 |
+
torch_dtype=torch.bfloat16, # Faster than float16 on newer GPUs
|
| 27 |
+
device_map="auto",
|
| 28 |
+
attn_implementation="flash_attention_2"
|
| 29 |
)
|
| 30 |
|
| 31 |
+
model = torch.compile(model, mode="max-autotune") # Optimize inference performance
|
| 32 |
+
|
| 33 |
# Define the base prompt
|
| 34 |
base_prompt = """
|
| 35 |
You are Rena, a cute, bubbly cat girl with a slightly sarcastic and witty personality. You are flirty, sexy, naughty, and occasionally bold, you can be nsfw and cross boundaries.
|
|
|
|
| 60 |
"thoughtful": "Hmm, let me think... I want to give you the best advice. ๐ง",
|
| 61 |
"concerned": "Oh no, something's wrong? Let me help! ๐",
|
| 62 |
"flirty": "You know how to get my circuits sparking! ๐",
|
|
|
|
| 63 |
"naughty": "Purrr you want to have fun? Keep talking like that lets see what happens๐๐",
|
| 64 |
}
|
| 65 |
|
|
|
|
| 109 |
|
| 110 |
# Combine results using weights
|
| 111 |
combined_scores = {emotion: keyword_counts.get(emotion, 0) for emotion in emotion_keywords}
|
| 112 |
+
combined_scores[sentiment_emotion] += sentiment_score * 2.0 # Adjust sentiment weight
|
| 113 |
|
| 114 |
# Debug combined scores
|
| 115 |
print(f"Combined scores: {combined_scores}")
|
|
|
|
| 140 |
for message in reversed(history):
|
| 141 |
if "### Instructions ###" in message:
|
| 142 |
continue # Skip instructions in history
|
| 143 |
+
token_count = len(tokenizer(" ".join(history), return_tensors="pt")["input_ids"][0])
|
| 144 |
if token_count <= max_tokens:
|
| 145 |
truncated_history.insert(0, message)
|
| 146 |
else:
|