Wonder-Griffin commited on
Commit
1c2c466
·
verified ·
1 Parent(s): 2985c75

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -8
app.py CHANGED
@@ -1,11 +1,19 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
 
 
 
8
 
 
 
 
9
 
10
  def respond(
11
  message,
@@ -25,7 +33,7 @@ def respond(
25
 
26
  messages.append({"role": "user", "content": message})
27
 
28
- response = ""
29
 
30
  for message in client.chat_completion(
31
  messages,
@@ -36,8 +44,8 @@ def respond(
36
  ):
37
  token = message.choices[0].delta.content
38
 
39
- response += token
40
- yield response
41
 
42
  """
43
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
1
  import gradio as gr
 
2
 
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer
4
+
5
+ model_path = "Wonder-Griffin/ShorseyBeerLeague"
6
+
7
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
8
+ model = AutoModelForCausalLM.from_pretrained(
9
+ model_path,
10
+ device_map="auto",
11
+ torch_dtype='auto'
12
+ ).eval()
13
 
14
+ input_ids = tokenizer.apply_chat_template(conversation=messages, tokenize=True, add_generation_prompt=True, return_tensors='pt')
15
+ output_ids = model.generate(input_ids.to('cuda'))
16
+ respond = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
17
 
18
  def respond(
19
  message,
 
33
 
34
  messages.append({"role": "user", "content": message})
35
 
36
+ respond = tokenizer.decode(output_ids[0][input_ids.shape[1]:], skip_special_tokens=True)
37
 
38
  for message in client.chat_completion(
39
  messages,
 
44
  ):
45
  token = message.choices[0].delta.content
46
 
47
+ respond += token
48
+ yield respond
49
 
50
  """
51
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface