- app.py +21 -31
- requirements.txt +3 -3
app.py
CHANGED
@@ -1,37 +1,27 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
# Specify the model paths
|
4 |
-
base_model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
|
5 |
-
fine_tuned_model_name = "cheberle/autotrain-35swc-b4r9z"
|
6 |
-
|
7 |
-
# Load the tokenizer
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained(base_model_name, trust_remote_code=True)
|
9 |
-
|
10 |
-
# Load the base model with fine-tuned weights
|
11 |
-
model = AutoModelForCausalLM.from_pretrained(
|
12 |
-
fine_tuned_model_name,
|
13 |
-
device_map="auto",
|
14 |
-
torch_dtype="auto",
|
15 |
-
trust_remote_code=True
|
16 |
-
)
|
17 |
|
18 |
-
#
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
-
return response
|
24 |
|
25 |
-
|
26 |
-
|
|
|
|
|
|
|
|
|
|
|
27 |
|
|
|
28 |
interface = gr.Interface(
|
29 |
-
fn=
|
30 |
-
inputs=gr.Textbox(
|
31 |
-
outputs="
|
32 |
-
title="
|
33 |
-
description="
|
34 |
)
|
35 |
|
36 |
-
|
37 |
-
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Load the model and tokenizer
|
5 |
+
model_name = "deepseek-ai/DeepSeek-R1"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
|
|
8 |
|
9 |
+
def classify_text(input_text):
|
10 |
+
# Tokenize the input
|
11 |
+
inputs = tokenizer(input_text, return_tensors="pt")
|
12 |
+
# Get predictions
|
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 the Gradio interface
|
18 |
interface = gr.Interface(
|
19 |
+
fn=classify_text,
|
20 |
+
inputs=gr.Textbox(label="Enter Text"),
|
21 |
+
outputs=gr.Label(label="Class Probabilities"),
|
22 |
+
title="DeepSeek-R1 Text Classification",
|
23 |
+
description="A text classification app powered by DeepSeek-R1."
|
24 |
)
|
25 |
|
26 |
+
# Launch the app
|
27 |
+
interface.launch()
|
requirements.txt
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
huggingface_hub==0.25.2
|
2 |
transformers
|
3 |
-
|
4 |
-
|
5 |
-
|
|
|
1 |
huggingface_hub==0.25.2
|
2 |
transformers
|
3 |
+
torch
|
4 |
+
datasets
|
5 |
+
scipy
|