Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -32,10 +32,10 @@ if not torch.cuda.is_available():
|
|
32 |
# Model and Tokenizer Configuration
|
33 |
model_id = "meta-llama/Llama-2-7b-hf"
|
34 |
bnb_config = BitsAndBytesConfig(
|
35 |
-
|
36 |
bnb_4bit_use_double_quant=False,
|
37 |
-
|
38 |
-
|
39 |
)
|
40 |
base_model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", quantization_config=bnb_config)
|
41 |
model = PeftModel.from_pretrained(base_model, "ranamhamoud/storytell")
|
@@ -58,11 +58,6 @@ def make_prompt(entry):
|
|
58 |
# f"TELL A STORY, RELATE TO COMPUTER SCIENCE, INCLUDE ASSESMENTS. MAKE IT REALISTIC AND AROUND 800 WORDS: {entry}"
|
59 |
|
60 |
def process_text(text):
|
61 |
-
# Bold specific bracketed phrases
|
62 |
-
text = re.sub(r'\[(assessment.*?)]', r'**[\1]**', text, flags=re.IGNORECASE)
|
63 |
-
text = re.sub(r'\[(answer.*?)]', r'**[\1]**', text, flags=re.IGNORECASE)
|
64 |
-
|
65 |
-
# Remove all other bracketed content
|
66 |
text = re.sub(r'\[.*?\]', '', text) # Removes any text in square brackets
|
67 |
text = re.sub(r'\(.*?\)', '', text) # Removes any text in round brackets
|
68 |
text = re.sub(r'\{.*?\}', '', text) # Removes any text in curly brackets
|
@@ -75,7 +70,7 @@ def generate(
|
|
75 |
message: str,
|
76 |
chat_history: list[tuple[str, str]],
|
77 |
max_new_tokens: int = DEFAULT_MAX_NEW_TOKENS,
|
78 |
-
temperature: float = 0.
|
79 |
top_p: float = 0.7,
|
80 |
top_k: int = 20,
|
81 |
repetition_penalty: float = 1.0,
|
|
|
32 |
# Model and Tokenizer Configuration
|
33 |
model_id = "meta-llama/Llama-2-7b-hf"
|
34 |
bnb_config = BitsAndBytesConfig(
|
35 |
+
load_in_8bit=True,
|
36 |
bnb_4bit_use_double_quant=False,
|
37 |
+
bnb_8bit_quant_type="nf8",
|
38 |
+
bnb_8bit_compute_dtype=torch.bfloat16
|
39 |
)
|
40 |
base_model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", quantization_config=bnb_config)
|
41 |
model = PeftModel.from_pretrained(base_model, "ranamhamoud/storytell")
|
|
|
58 |
# f"TELL A STORY, RELATE TO COMPUTER SCIENCE, INCLUDE ASSESMENTS. MAKE IT REALISTIC AND AROUND 800 WORDS: {entry}"
|
59 |
|
60 |
def process_text(text):
|
|
|
|
|
|
|
|
|
|
|
61 |
text = re.sub(r'\[.*?\]', '', text) # Removes any text in square brackets
|
62 |
text = re.sub(r'\(.*?\)', '', text) # Removes any text in round brackets
|
63 |
text = re.sub(r'\{.*?\}', '', text) # Removes any text in curly brackets
|
|
|
70 |
message: str,
|
71 |
chat_history: list[tuple[str, str]],
|
72 |
max_new_tokens: int = DEFAULT_MAX_NEW_TOKENS,
|
73 |
+
temperature: float = 0.6,
|
74 |
top_p: float = 0.7,
|
75 |
top_k: int = 20,
|
76 |
repetition_penalty: float = 1.0,
|