app.py
CHANGED
@@ -1,20 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import AutoTokenizer
|
|
|
3 |
|
4 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
model_name = "deepseek-ai/DeepSeek-R1"
|
6 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
7 |
-
|
|
|
8 |
|
9 |
def classify_text(input_text):
|
10 |
-
# Tokenize
|
11 |
inputs = tokenizer(input_text, return_tensors="pt")
|
12 |
-
# Get
|
13 |
outputs = model(**inputs)
|
14 |
probabilities = outputs.logits.softmax(dim=-1).detach().numpy()
|
15 |
return {f"Class {i}": prob for i, prob in enumerate(probabilities[0])}
|
16 |
|
17 |
-
# Create
|
18 |
interface = gr.Interface(
|
19 |
fn=classify_text,
|
20 |
inputs=gr.Textbox(label="Enter Text"),
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer
|
3 |
+
from transformers.utils import logging
|
4 |
|
5 |
+
# Enable logging to see debug messages
|
6 |
+
logging.set_verbosity_info()
|
7 |
+
|
8 |
+
# Import custom configuration and model classes
|
9 |
+
from transformers_modules.deepseek_ai.DeepSeek_R1.configuration_deepseek import DeepseekV3Config
|
10 |
+
from transformers_modules.deepseek_ai.DeepSeek_R1.modeling_deepseek import DeepseekV3Model
|
11 |
+
|
12 |
+
# Load model and tokenizer
|
13 |
model_name = "deepseek-ai/DeepSeek-R1"
|
14 |
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
15 |
+
config = DeepseekV3Config.from_pretrained(model_name, trust_remote_code=True)
|
16 |
+
model = DeepseekV3Model.from_pretrained(model_name, config=config, trust_remote_code=True)
|
17 |
|
18 |
def classify_text(input_text):
|
19 |
+
# Tokenize input
|
20 |
inputs = tokenizer(input_text, return_tensors="pt")
|
21 |
+
# Get model output
|
22 |
outputs = model(**inputs)
|
23 |
probabilities = outputs.logits.softmax(dim=-1).detach().numpy()
|
24 |
return {f"Class {i}": prob for i, prob in enumerate(probabilities[0])}
|
25 |
|
26 |
+
# Create Gradio interface
|
27 |
interface = gr.Interface(
|
28 |
fn=classify_text,
|
29 |
inputs=gr.Textbox(label="Enter Text"),
|