cheberle commited on
Commit
24e4297
·
1 Parent(s): 3a12042
Files changed (2) hide show
  1. app.py +28 -21
  2. requirements.txt +3 -2
app.py CHANGED
@@ -1,29 +1,36 @@
1
  from transformers import AutoModelForCausalLM, AutoTokenizer
 
2
 
3
- model_path = "cheberle/autotrain-35swc-b4r9z"
 
 
4
 
5
- # Load the tokenizer and model
6
- tokenizer = AutoTokenizer.from_pretrained(model_path)
 
 
7
  model = AutoModelForCausalLM.from_pretrained(
8
- model_path,
9
- device_map="auto", # Auto-distributes model across available devices
10
- torch_dtype="auto" # Automatically selects the appropriate data type
11
- ).eval()
12
 
13
- # Prompt content
14
- messages = [{"role": "user", "content": "hi"}]
 
 
 
 
15
 
16
- # Prepare input for the model
17
- input_ids = tokenizer.apply_chat_template(
18
- conversation=messages,
19
- tokenize=True,
20
- add_generation_prompt=True,
21
- return_tensors='pt'
 
22
  )
23
 
24
- # Generate response
25
- output_ids = model.generate(input_ids.to('cuda')) # Ensure the model uses the GPU if available
26
- response = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
27
-
28
- # Print response
29
- print(response)
 
1
  from transformers import AutoModelForCausalLM, AutoTokenizer
2
+ import gradio as gr
3
 
4
+ # Define the model paths
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(fine_tuned_model_name)
10
+
11
+ # Load the model
12
  model = AutoModelForCausalLM.from_pretrained(
13
+ fine_tuned_model_name,
14
+ device_map="auto", # Auto-distributes model across devices
15
+ torch_dtype="auto", # Matches model precision
16
+ )
17
 
18
+ # Define the chat function
19
+ def chat(input_text):
20
+ input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda") # Move input to GPU
21
+ output = model.generate(input_ids, max_length=100)
22
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
23
+ return response
24
 
25
+ # Create a Gradio interface
26
+ interface = gr.Interface(
27
+ fn=chat,
28
+ inputs=gr.Textbox(lines=2, placeholder="Type your input here..."),
29
+ outputs="text",
30
+ title="Chat with DeepSeek-AutoTrain Model",
31
+ description="Fine-tuned version of DeepSeek-R1-Distill-Qwen-7B. Ask me anything!",
32
  )
33
 
34
+ # Launch the interface
35
+ if __name__ == "__main__":
36
+ interface.launch()
 
 
 
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  huggingface_hub==0.25.2
2
  transformers
3
- torch
4
- accelerate
 
 
1
  huggingface_hub==0.25.2
2
  transformers
3
+ accelerate
4
+ gradio
5
+ torch