- app.py +23 -26
- requirements.txt +2 -2
app.py
CHANGED
@@ -1,32 +1,29 @@
|
|
1 |
-
import
|
2 |
-
from transformers import AutoTokenizer, AutoConfig, AutoModelForSequenceClassification
|
3 |
|
4 |
-
|
5 |
-
model_name = "cheberle/autotrain-35swc-b4r9z"
|
6 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
model =
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
inputs = tokenizer(input_text, return_tensors="pt", padding=True, truncation=True)
|
15 |
-
outputs = model(**inputs)
|
16 |
-
probabilities = outputs.logits.softmax(dim=-1).tolist()[0]
|
17 |
-
labels = {i: f"Label {i}" for i in range(len(probabilities))} # Define label mapping if needed
|
18 |
-
result = {labels[i]: prob for i, prob in enumerate(probabilities)}
|
19 |
-
return result
|
20 |
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
description="Classify text inputs using the DeepSeek-R1 model."
|
28 |
)
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
2 |
|
3 |
+
model_path = "cheberle/autotrain-35swc-b4r9z"
|
|
|
|
|
4 |
|
5 |
+
# Load the tokenizer and model
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(
|
8 |
+
model_path,
|
9 |
+
device_map="auto", # Auto-distributes model across available devices
|
10 |
+
torch_dtype="auto" # Automatically selects the appropriate data type
|
11 |
+
).eval()
|
12 |
|
13 |
+
# Prompt content
|
14 |
+
messages = [{"role": "user", "content": "hi"}]
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
+
# Prepare input for the model
|
17 |
+
input_ids = tokenizer.apply_chat_template(
|
18 |
+
conversation=messages,
|
19 |
+
tokenize=True,
|
20 |
+
add_generation_prompt=True,
|
21 |
+
return_tensors='pt'
|
|
|
22 |
)
|
23 |
|
24 |
+
# Generate response
|
25 |
+
output_ids = model.generate(input_ids.to('cuda')) # Ensure the model uses the GPU if available
|
26 |
+
response = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
|
27 |
+
|
28 |
+
# Print response
|
29 |
+
print(response)
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
huggingface_hub==0.25.2
|
2 |
-
|
3 |
torch
|
4 |
-
|
|
|
1 |
huggingface_hub==0.25.2
|
2 |
+
transformers
|
3 |
torch
|
4 |
+
accelerate
|