簡嘉琳
commited on
Commit
·
da4f073
1
Parent(s):
bb42d34
Merge
Browse files- app.py +9 -11
- requirements.txt +0 -5
app.py
CHANGED
@@ -9,21 +9,15 @@ MODEL_NAMES = {
|
|
9 |
}
|
10 |
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
12 |
-
<<<<<<< HEAD
|
13 |
|
14 |
|
15 |
def load_model(model_path):
|
16 |
tokenizer = AutoTokenizer.from_pretrained(
|
17 |
model_path, trust_remote_code=True, token=HF_TOKEN
|
18 |
)
|
19 |
-
|
20 |
-
model_path,
|
21 |
-
)
|
22 |
-
=======
|
23 |
-
|
24 |
-
def load_model(model_path):
|
25 |
-
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True, token=HF_TOKEN)
|
26 |
-
config = AutoConfig.from_pretrained(model_path, trust_remote_code=True, token=HF_TOKEN)
|
27 |
if hasattr(config, "quantization_config"):
|
28 |
del config.quantization_config # 刪除量化配置,避免使用 FP8
|
29 |
|
@@ -35,13 +29,14 @@ def load_model(model_path):
|
|
35 |
torch_dtype=torch.float16,
|
36 |
device_map="auto",
|
37 |
)
|
38 |
-
>>>>>>> c4a529954b9cc11b7b8c2dcdac51f3ef3a83c616
|
39 |
return model, tokenizer
|
40 |
|
|
|
41 |
# 初始化預設模型
|
42 |
current_model_name = "DeepSeek-R1-Distill-Llama-8B"
|
43 |
current_model, current_tokenizer = load_model(MODEL_NAMES[current_model_name])
|
44 |
|
|
|
45 |
def chat(message, history, model_name):
|
46 |
global current_model, current_tokenizer, current_model_name
|
47 |
|
@@ -57,6 +52,7 @@ def chat(message, history, model_name):
|
|
57 |
|
58 |
return response
|
59 |
|
|
|
60 |
with gr.Blocks() as app:
|
61 |
gr.Markdown("## Chatbot with DeepSeek Models")
|
62 |
|
@@ -73,6 +69,8 @@ with gr.Blocks() as app:
|
|
73 |
save_history=True,
|
74 |
)
|
75 |
|
76 |
-
model_selector.change(
|
|
|
|
|
77 |
|
78 |
app.launch()
|
|
|
9 |
}
|
10 |
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
12 |
|
13 |
|
14 |
def load_model(model_path):
|
15 |
tokenizer = AutoTokenizer.from_pretrained(
|
16 |
model_path, trust_remote_code=True, token=HF_TOKEN
|
17 |
)
|
18 |
+
config = AutoConfig.from_pretrained(
|
19 |
+
model_path, trust_remote_code=True, token=HF_TOKEN
|
20 |
+
)
|
|
|
|
|
|
|
|
|
|
|
21 |
if hasattr(config, "quantization_config"):
|
22 |
del config.quantization_config # 刪除量化配置,避免使用 FP8
|
23 |
|
|
|
29 |
torch_dtype=torch.float16,
|
30 |
device_map="auto",
|
31 |
)
|
|
|
32 |
return model, tokenizer
|
33 |
|
34 |
+
|
35 |
# 初始化預設模型
|
36 |
current_model_name = "DeepSeek-R1-Distill-Llama-8B"
|
37 |
current_model, current_tokenizer = load_model(MODEL_NAMES[current_model_name])
|
38 |
|
39 |
+
|
40 |
def chat(message, history, model_name):
|
41 |
global current_model, current_tokenizer, current_model_name
|
42 |
|
|
|
52 |
|
53 |
return response
|
54 |
|
55 |
+
|
56 |
with gr.Blocks() as app:
|
57 |
gr.Markdown("## Chatbot with DeepSeek Models")
|
58 |
|
|
|
69 |
save_history=True,
|
70 |
)
|
71 |
|
72 |
+
model_selector.change(
|
73 |
+
fn=lambda model_name: None, inputs=[model_selector], outputs=[]
|
74 |
+
)
|
75 |
|
76 |
app.launch()
|
requirements.txt
CHANGED
@@ -1,8 +1,3 @@
|
|
1 |
-
<<<<<<< HEAD
|
2 |
-
transformers>=4.37.2
|
3 |
-
torch>=2.1.0
|
4 |
-
=======
|
5 |
transformers>=4.38.0
|
6 |
torch>=2.1.0
|
7 |
accelerate
|
8 |
-
>>>>>>> c4a529954b9cc11b7b8c2dcdac51f3ef3a83c616
|
|
|
|
|
|
|
|
|
|
|
1 |
transformers>=4.38.0
|
2 |
torch>=2.1.0
|
3 |
accelerate
|
|