BasToTheMax commited on
Commit
aff5a59
1 Parent(s): 94d1bc9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -15
app.py CHANGED
@@ -1,10 +1,14 @@
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(
@@ -27,17 +31,11 @@ def respond(
27
 
28
  response = ""
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
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
  from huggingface_hub import InferenceClient
3
 
4
+ # pip install bitsandbytes accelerate
5
+ from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
6
+ # to use 4bit use `load_in_4bit=True` instead
7
+ quantization_config = BitsAndBytesConfig(load_in_8bit=True)
8
+ checkpoint = "HuggingFaceTB/SmolLM-135M"
9
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
10
+ model = AutoModelForCausalLM.from_pretrained(checkpoint, quantization_config=quantization_config)
11
+
12
 
13
 
14
  def respond(
 
31
 
32
  response = ""
33
 
34
+ inputs = tokenizer.encode(messages, return_tensors="pt").to("cuda")
35
+ outputs = model.generate(inputs)
36
+ print(tokenizer.decode(outputs[0]))
37
+
38
+ return tokenizer.decode(outputs[0])
 
 
 
 
 
 
39
 
40
  """
41
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface