Spaces:
Runtime error
Runtime error
BasToTheMax
commited on
Commit
•
aff5a59
1
Parent(s):
94d1bc9
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
from huggingface_hub import InferenceClient
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
|
9 |
|
10 |
def respond(
|
@@ -27,17 +31,11 @@ def respond(
|
|
27 |
|
28 |
response = ""
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
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
|