Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,41 @@
|
|
1 |
-
from
|
2 |
-
|
3 |
import os
|
4 |
|
5 |
os.environ['HF_HOME'] = '/tmp/cache'
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
|
|
12 |
)
|
13 |
|
14 |
-
#
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
2 |
+
import torch
|
3 |
import os
|
4 |
|
5 |
os.environ['HF_HOME'] = '/tmp/cache'
|
6 |
|
7 |
+
# Load model and tokenizer
|
8 |
+
model_id = "Disya/DS-R1-Qwen3-8B-ArliAI-RpR-v4-exl2-8bpw-h8"
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
11 |
+
model_id,
|
12 |
+
device_map="auto",
|
13 |
+
torch_dtype=torch.float16
|
14 |
)
|
15 |
|
16 |
+
# Create text generation pipeline
|
17 |
+
pipe = pipeline(
|
18 |
+
"text-generation",
|
19 |
+
model=model,
|
20 |
+
tokenizer=tokenizer,
|
21 |
+
max_new_tokens=1080
|
22 |
+
)
|
23 |
+
|
24 |
+
def generate_chat_completion(messages, max_tokens=1080, temperature=0.8):
|
25 |
+
"""Generate chat response in OpenAI format"""
|
26 |
+
# Format messages as prompt
|
27 |
+
prompt = tokenizer.apply_chat_template(
|
28 |
+
messages,
|
29 |
+
tokenize=False,
|
30 |
+
add_generation_prompt=True
|
31 |
+
)
|
32 |
+
|
33 |
+
# Generate response
|
34 |
+
outputs = pipe(
|
35 |
+
prompt,
|
36 |
+
max_new_tokens=max_tokens,
|
37 |
+
temperature=temperature,
|
38 |
+
do_sample=True
|
39 |
+
)
|
40 |
+
|
41 |
+
return outputs[0]["generated_text"]
|