Spaces:
Sleeping
Sleeping
Commit
·
dad4e7a
1
Parent(s):
d28a2a4
feat: change logic
Browse files- src/streamlit_app.py +25 -25
src/streamlit_app.py
CHANGED
|
@@ -5,35 +5,35 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 5 |
# from huggingface_hub import notebook_login
|
| 6 |
# from unsloth import FastLanguageModel, is_bfloat16_supported
|
| 7 |
|
| 8 |
-
model_id = "sentence-transformers/all-MiniLM-L6-v2"
|
| 9 |
# model_id = "sentence-transformers/xlm-r-base-en-ko-nli-ststb"
|
| 10 |
|
| 11 |
# model_id = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 12 |
# model_id = "meta-llama/Llama-3.2-1B"
|
| 13 |
-
|
| 14 |
|
| 15 |
-
# processor = pipeline(
|
| 16 |
-
# "text-generation",
|
| 17 |
-
# model=model_id,
|
| 18 |
-
# model_kwargs={
|
| 19 |
-
# "torch_dtype": torch.float16,
|
| 20 |
-
# "quantization_config": {"load_in_4bit": True},
|
| 21 |
-
# "low_cpu_mem_usage": True,
|
| 22 |
-
# },
|
| 23 |
-
# )
|
| 24 |
-
# terminators = [
|
| 25 |
-
# processor.tokenizer.eos_token_id,
|
| 26 |
-
# processor.tokenizer.convert_tokens_to_ids(""),
|
| 27 |
-
# ]
|
| 28 |
-
|
| 29 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 30 |
-
model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 31 |
processor = pipeline(
|
| 32 |
"text-generation",
|
| 33 |
-
model=
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
| 36 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
|
| 39 |
def main():
|
|
@@ -55,11 +55,11 @@ def main():
|
|
| 55 |
prompt = processor.tokenizer.apply_chat_template(
|
| 56 |
user_prompt, tokenize=False, add_generation_prompt=True)
|
| 57 |
# prompt = user_prompt
|
| 58 |
-
outputs = processor(prompt)
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
response = outputs[0]["generated_text"][len(prompt):]
|
| 64 |
st.write(response)
|
| 65 |
|
|
|
|
| 5 |
# from huggingface_hub import notebook_login
|
| 6 |
# from unsloth import FastLanguageModel, is_bfloat16_supported
|
| 7 |
|
| 8 |
+
# model_id = "sentence-transformers/all-MiniLM-L6-v2"
|
| 9 |
# model_id = "sentence-transformers/xlm-r-base-en-ko-nli-ststb"
|
| 10 |
|
| 11 |
# model_id = "mistralai/Mistral-7B-Instruct-v0.1"
|
| 12 |
# model_id = "meta-llama/Llama-3.2-1B"
|
| 13 |
+
model_id = "choco-conoz/TwinLlama-3.1-8B"
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
processor = pipeline(
|
| 16 |
"text-generation",
|
| 17 |
+
model=model_id,
|
| 18 |
+
model_kwargs={
|
| 19 |
+
"torch_dtype": torch.float16,
|
| 20 |
+
"quantization_config": {"load_in_4bit": True},
|
| 21 |
+
"low_cpu_mem_usage": True,
|
| 22 |
+
},
|
| 23 |
)
|
| 24 |
+
terminators = [
|
| 25 |
+
processor.tokenizer.eos_token_id,
|
| 26 |
+
processor.tokenizer.convert_tokens_to_ids(""),
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
# tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 30 |
+
# model = AutoModelForCausalLM.from_pretrained(model_id)
|
| 31 |
+
# processor = pipeline(
|
| 32 |
+
# "text-generation",
|
| 33 |
+
# model=model,
|
| 34 |
+
# tokenizer=tokenizer,
|
| 35 |
+
# max_new_tokens=10
|
| 36 |
+
# )
|
| 37 |
|
| 38 |
|
| 39 |
def main():
|
|
|
|
| 55 |
prompt = processor.tokenizer.apply_chat_template(
|
| 56 |
user_prompt, tokenize=False, add_generation_prompt=True)
|
| 57 |
# prompt = user_prompt
|
| 58 |
+
# outputs = processor(prompt)
|
| 59 |
|
| 60 |
+
outputs = processor(prompt, max_new_tokens=4096, eos_token_id=terminators, do_sample=True,
|
| 61 |
+
temperature=0.6, top_p=0.9
|
| 62 |
+
)
|
| 63 |
response = outputs[0]["generated_text"][len(prompt):]
|
| 64 |
st.write(response)
|
| 65 |
|