Spaces:
Runtime error
Runtime error
Create proxy_model.py
Browse files- proxy_model.py +27 -0
proxy_model.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import requests
|
3 |
+
import torch
|
4 |
+
from transformers import AutoTokenizer, AutoConfig, AutoModelForCausalLM
|
5 |
+
|
6 |
+
class RemoteModelProxy:
|
7 |
+
def __init__(self, model_id):
|
8 |
+
self.model_id = model_id
|
9 |
+
self.tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
|
10 |
+
self.config = AutoConfig.from_pretrained(model_id, trust_remote_code=True)
|
11 |
+
self.model = AutoModelForCausalLM.from_pretrained(model_id, config=self.config, trust_remote_code=True)
|
12 |
+
|
13 |
+
def classify_text(self, text):
|
14 |
+
inputs = self.tokenizer(text, return_tensors="pt", padding=True, truncation=True)
|
15 |
+
logits = self.model(**inputs)
|
16 |
+
probabilities = torch.softmax(logits, dim=-1).tolist()[0]
|
17 |
+
predicted_class = torch.argmax(logits, dim=-1).item()
|
18 |
+
return {
|
19 |
+
"Predicted Class": predicted_class,
|
20 |
+
"Probabilities": probabilities
|
21 |
+
}
|
22 |
+
|
23 |
+
if __name__ == "__main__":
|
24 |
+
model_id = "deepseek-ai/DeepSeek-V3"
|
25 |
+
proxy = RemoteModelProxy(model_id)
|
26 |
+
result = proxy.classify_text("Your input text here")
|
27 |
+
print(result)
|