liang1234 commited on
Commit
77a56ed
·
verified ·
1 Parent(s): ff73263

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -1,13 +1,10 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
- from transformers import AutoTokenizer, AutoModelForCausalLM
4
 
5
- tokenizer = AutoTokenizer.from_pretrained("google/gemma-2-2b")
6
- model = AutoModelForCausalLM.from_pretrained("google/gemma-2-2b")
7
  """
8
  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
9
  """
10
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
11
 
12
 
13
  def respond(
@@ -28,23 +25,20 @@ def respond(
28
 
29
  messages.append({"role": "user", "content": message})
30
  response = ""
31
- inputs = tokenizer(message, return_tensors="pt")
32
-
33
- generate_ids = model.generate(inputs.input_ids, max_length=30)
34
- response = tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
35
  # Load model directly
36
- yield response
37
- # for message in client.chat_completion(
38
- # messages,
39
- # max_tokens=max_tokens,
40
- # stream=True,
41
- # temperature=temperature,
42
- # top_p=top_p,
43
- # ):
44
- # token = message.choices[0].delta.content
45
 
46
- # response += token
47
- # yield response
 
 
 
 
 
 
 
 
 
48
 
49
  """
50
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
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("google/gemma-2-2b")
8
 
9
 
10
  def respond(
 
25
 
26
  messages.append({"role": "user", "content": message})
27
  response = ""
28
+
 
 
 
29
  # Load model directly
 
 
 
 
 
 
 
 
 
30
 
31
+ for message in client.chat_completion(
32
+ messages,
33
+ max_tokens=max_tokens,
34
+ stream=True,
35
+ temperature=temperature,
36
+ top_p=top_p,
37
+ ):
38
+ token = message.choices[0].delta.content
39
+
40
+ response += token
41
+ yield response
42
 
43
  """
44
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface