app.py
CHANGED
@@ -1,36 +1,37 @@
|
|
1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
2 |
-
import gradio as gr
|
3 |
|
4 |
-
#
|
5 |
base_model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-7B"
|
6 |
fine_tuned_model_name = "cheberle/autotrain-35swc-b4r9z"
|
7 |
|
8 |
# Load the tokenizer
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained(
|
10 |
|
11 |
-
# Load the model
|
12 |
model = AutoModelForCausalLM.from_pretrained(
|
13 |
fine_tuned_model_name,
|
14 |
-
device_map="auto",
|
15 |
-
torch_dtype="auto",
|
|
|
16 |
)
|
17 |
|
18 |
-
# Define
|
19 |
def chat(input_text):
|
20 |
-
|
21 |
-
|
22 |
-
response = tokenizer.decode(
|
23 |
return response
|
24 |
|
25 |
-
#
|
|
|
|
|
26 |
interface = gr.Interface(
|
27 |
fn=chat,
|
28 |
-
inputs=gr.Textbox(lines=2, placeholder="Type your
|
29 |
outputs="text",
|
30 |
-
title="Chat with DeepSeek-
|
31 |
-
description="
|
32 |
)
|
33 |
|
34 |
-
# Launch the interface
|
35 |
if __name__ == "__main__":
|
36 |
interface.launch()
|
|
|
1 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
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 |
+
# Define a simple function for chat
|
19 |
def chat(input_text):
|
20 |
+
inputs = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
|
21 |
+
outputs = model.generate(inputs, max_length=100, temperature=0.7)
|
22 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
23 |
return response
|
24 |
|
25 |
+
# Gradio UI
|
26 |
+
import gradio as gr
|
27 |
+
|
28 |
interface = gr.Interface(
|
29 |
fn=chat,
|
30 |
+
inputs=gr.Textbox(lines=2, placeholder="Type your message here..."),
|
31 |
outputs="text",
|
32 |
+
title="Chat with DeepSeek Fine-tuned Model",
|
33 |
+
description="This is a fine-tuned version of the DeepSeek R1 Distill Qwen-7B model. Ask me anything!"
|
34 |
)
|
35 |
|
|
|
36 |
if __name__ == "__main__":
|
37 |
interface.launch()
|