Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,58 +1,7 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
warnings.filterwarnings("ignore", category=FutureWarning, module="torch")
|
9 |
-
|
10 |
-
# Load the model and tokenizer
|
11 |
-
model_name = "deepseek-ai/DeepSeek-V3"
|
12 |
-
revision = "main" # Specify the revision directly
|
13 |
-
|
14 |
-
print(f"Loading tokenizer from {model_name}...")
|
15 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name, revision=revision, trust_remote_code=True)
|
16 |
-
|
17 |
-
print(f"Loading configuration from {model_name}...")
|
18 |
-
config = AutoConfig.from_pretrained(model_name, revision=revision, trust_remote_code=True)
|
19 |
-
|
20 |
-
print(f"Loading model from {model_name}...")
|
21 |
-
model = CustomModel.from_pretrained(model_name, config=config, revision=revision, trust_remote_code=True)
|
22 |
-
|
23 |
-
if model is None:
|
24 |
-
print("Failed to load model.")
|
25 |
-
else:
|
26 |
-
print("Model loaded successfully.")
|
27 |
-
|
28 |
-
def classify_text(text):
|
29 |
-
inputs = tokenizer(text, return_tensors="pt")
|
30 |
-
outputs = model(**inputs)
|
31 |
-
logits = outputs.logits
|
32 |
-
probabilities = torch.softmax(logits, dim=-1).tolist()[0]
|
33 |
-
predicted_class = torch.argmax(logits, dim=-1).item()
|
34 |
-
return {
|
35 |
-
"Predicted Class": predicted_class,
|
36 |
-
"Probabilities": probabilities
|
37 |
-
}
|
38 |
-
|
39 |
-
# Create a Gradio interface
|
40 |
-
try:
|
41 |
-
iface = gr.Interface(
|
42 |
-
fn=classify_text,
|
43 |
-
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter text here..."), # Corrected here
|
44 |
-
outputs=[
|
45 |
-
gr.outputs.Label(label="Predicted Class"),
|
46 |
-
gr.outputs.Label(label="Probabilities")
|
47 |
-
],
|
48 |
-
title="DeepSeek-V3 Text Classification",
|
49 |
-
description="Classify text using the DeepSeek-V3 model."
|
50 |
-
)
|
51 |
-
except Exception as e:
|
52 |
-
print(f"Failed to create Gradio interface: {e}")
|
53 |
-
|
54 |
-
# Launch the interface
|
55 |
-
try:
|
56 |
-
iface.launch()
|
57 |
-
except Exception as e:
|
58 |
-
print(f"Failed to launch Gradio interface: {e}")
|
|
|
1 |
+
Loading model from deepseek-ai/DeepSeek-V3...
|
2 |
+
/home/user/app/custom_model.py:20: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
|
3 |
+
model.load_state_dict(torch.load(pretrained_model_name_or_path))
|
4 |
+
Failed to load model from deepseek-ai/DeepSeek-V3. Please check the model name and path.
|
5 |
+
Failed to load model.
|
6 |
+
Failed to create Gradio interface: module 'gradio' has no attribute 'inputs'
|
7 |
+
Failed to launch Gradio interface: name 'iface' is not defined
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|