Alejadro Sanchez-Giraldo commited on
Commit
c585826
·
1 Parent(s): 8b6f519

add deepSeek code completions

Browse files
Files changed (2) hide show
  1. app.py +19 -3
  2. dice.py +21 -0
app.py CHANGED
@@ -1,6 +1,15 @@
1
  import gradio as gr
2
  from fpl_client import FPLClient
3
  from nlp_utils import process_query
 
 
 
 
 
 
 
 
 
4
 
5
  # Theme builder
6
  # gr.themes.builder()
@@ -19,8 +28,14 @@ def chatbot_response(query):
19
  # if response if a JSON boject iterate over the elements and conver is a list like "a": "b" "/n" "c": "d"
20
  if isinstance(response, dict):
21
  response = "\n".join([f"{key}: {value}" for key, value in response.items()])
22
- return response
23
-
 
 
 
 
 
 
24
 
25
  # Set up the Gradio interface
26
  iface = gr.Interface(
@@ -30,5 +45,6 @@ iface = gr.Interface(
30
  theme=theme,
31
  title="FPL Chatbot"
32
  )
 
33
  if __name__ == "__main__":
34
- iface.launch()
 
1
  import gradio as gr
2
  from fpl_client import FPLClient
3
  from nlp_utils import process_query
4
+ from transformers import AutoTokenizer, AutoModelForCausalLM
5
+ import torch
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-coder-1.3b-instruct", trust_remote_code=True)
8
+ model = AutoModelForCausalLM.from_pretrained("deepseek-ai/deepseek-coder-1.3b-instruct", trust_remote_code=True, torch_dtype=torch.bfloat16)
9
+
10
+ # Use CPU if CUDA is not available
11
+ device = torch.device("cpu")
12
+ model = model.to(device)
13
 
14
  # Theme builder
15
  # gr.themes.builder()
 
28
  # if response if a JSON boject iterate over the elements and conver is a list like "a": "b" "/n" "c": "d"
29
  if isinstance(response, dict):
30
  response = "\n".join([f"{key}: {value}" for key, value in response.items()])
31
+
32
+ # Generate response using the model
33
+ messages = [{'role': 'user', 'content': query}]
34
+ inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
35
+ outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, top_k=50, top_p=0.95, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
36
+ model_response = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
37
+
38
+ return response + "\n\n" + model_response
39
 
40
  # Set up the Gradio interface
41
  iface = gr.Interface(
 
45
  theme=theme,
46
  title="FPL Chatbot"
47
  )
48
+
49
  if __name__ == "__main__":
50
+ iface.launch()
dice.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+
3
+ def roll_dice():
4
+ return random.randint(1, 6)
5
+
6
+ def main():
7
+ print("Welcome to the dice roller!")
8
+ while True:
9
+ print("Enter 'q' to quit.")
10
+ user_input = input("Roll the dice? ")
11
+ if user_input.lower() == 'q':
12
+ break
13
+ else:
14
+ try:
15
+ result = roll_dice()
16
+ print(f"You rolled a {result}!")
17
+ except ValueError:
18
+ print("Invalid input, please enter a number.")
19
+
20
+ if __name__ == "__main__":
21
+ main()