Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,16 +2,22 @@ import subprocess
|
|
2 |
import sys
|
3 |
|
4 |
# Cài đặt thư viện nếu chưa có
|
5 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", "transformers", "streamlit", "torch"])
|
6 |
|
7 |
import streamlit as st
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
|
|
|
9 |
import torch
|
10 |
|
11 |
-
#
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
def generate_response(prompt):
|
17 |
"""Generate a response from the model."""
|
@@ -49,4 +55,3 @@ if user_input:
|
|
49 |
|
50 |
# Append assistant response
|
51 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
52 |
-
|
|
|
2 |
import sys
|
3 |
|
4 |
# Cài đặt thư viện nếu chưa có
|
5 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "transformers", "streamlit", "torch", "peft"])
|
6 |
|
7 |
import streamlit as st
|
8 |
from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer
|
9 |
+
from peft import PeftModel
|
10 |
import torch
|
11 |
|
12 |
+
# Định nghĩa tên mô hình gốc và adapter
|
13 |
+
BASE_MODEL_NAME = "unsloth/deepseek-r1-distill-llama-8b-unsloth-bnb-4bit"
|
14 |
+
ADAPTER_MODEL_PATH = "lora_model"
|
15 |
+
|
16 |
+
# Load mô hình gốc
|
17 |
+
base_model = AutoModelForCausalLM.from_pretrained(BASE_MODEL_NAME, torch_dtype=torch.float16, device_map="auto")
|
18 |
+
# Áp dụng adapter LoRA
|
19 |
+
model = PeftModel.from_pretrained(base_model, ADAPTER_MODEL_PATH)
|
20 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL_NAME)
|
21 |
|
22 |
def generate_response(prompt):
|
23 |
"""Generate a response from the model."""
|
|
|
55 |
|
56 |
# Append assistant response
|
57 |
st.session_state.messages.append({"role": "assistant", "content": response})
|
|