Update app.py
Browse files
app.py
CHANGED
@@ -20,6 +20,17 @@ MODELS = {
|
|
20 |
"0.4B (Larger)": "RWKV-x070-World-0.4B-v2.9-20250107-ctx4096.pth"
|
21 |
}
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def download_model(model_name):
|
24 |
"""Download model if not present"""
|
25 |
if not os.path.exists(model_name):
|
@@ -48,11 +59,16 @@ class ModelManager:
|
|
48 |
def load_model(self, model_name):
|
49 |
if model_name != self.current_model_name:
|
50 |
download_model(MODELS[model_name])
|
51 |
-
self.current_model = RWKV(
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
self.current_model_name = model_name
|
54 |
return self.pipeline
|
55 |
|
|
|
56 |
model_manager = ModelManager()
|
57 |
|
58 |
def generate_response(
|
|
|
20 |
"0.4B (Larger)": "RWKV-x070-World-0.4B-v2.9-20250107-ctx4096.pth"
|
21 |
}
|
22 |
|
23 |
+
# Download tokenizer if not present
|
24 |
+
TOKENIZER_FILE = "rwkv_vocab_v20230424.txt"
|
25 |
+
TOKENIZER_URL = "https://raw.githubusercontent.com/BlinkDL/ChatRWKV/main/v2/rwkv_vocab_v20230424.txt"
|
26 |
+
|
27 |
+
def download_tokenizer():
|
28 |
+
if not os.path.exists(TOKENIZER_FILE):
|
29 |
+
print("Downloading tokenizer...")
|
30 |
+
response = requests.get(TOKENIZER_URL)
|
31 |
+
with open(TOKENIZER_FILE, 'wb') as f:
|
32 |
+
f.write(response.content)
|
33 |
+
|
34 |
def download_model(model_name):
|
35 |
"""Download model if not present"""
|
36 |
if not os.path.exists(model_name):
|
|
|
59 |
def load_model(self, model_name):
|
60 |
if model_name != self.current_model_name:
|
61 |
download_model(MODELS[model_name])
|
62 |
+
self.current_model = RWKV(
|
63 |
+
model=MODELS[model_name],
|
64 |
+
strategy='cpu fp32',
|
65 |
+
v7=True
|
66 |
+
)
|
67 |
+
self.pipeline = PIPELINE(self.current_model, TOKENIZER_FILE)
|
68 |
self.current_model_name = model_name
|
69 |
return self.pipeline
|
70 |
|
71 |
+
|
72 |
model_manager = ModelManager()
|
73 |
|
74 |
def generate_response(
|