Spaces:
Running
on
Zero
Running
on
Zero
Nihal Nayak
commited on
Commit
·
56f924f
1
Parent(s):
481eb0d
auto causal model
Browse files
app.py
CHANGED
@@ -1,12 +1,15 @@
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
from huggingface_hub import InferenceClient
|
|
|
4 |
|
5 |
"""
|
6 |
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
|
7 |
"""
|
8 |
-
client = InferenceClient("BatsResearch/bonito-v1")
|
9 |
-
|
|
|
|
|
10 |
|
11 |
@spaces.GPU
|
12 |
def respond(
|
@@ -20,7 +23,18 @@ def respond(
|
|
20 |
input_text = "<|tasktype|>\n" + task_type.strip()
|
21 |
input_text += "\n<|context|>\n" + message.strip() + "\n<|task|>\n"
|
22 |
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
return response
|
26 |
# messages = []
|
|
|
1 |
import gradio as gr
|
2 |
import spaces
|
3 |
from huggingface_hub import InferenceClient
|
4 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
|
6 |
"""
|
7 |
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
|
8 |
"""
|
9 |
+
# client = InferenceClient("BatsResearch/bonito-v1")
|
10 |
+
model = AutoModelForCausalLM.from_pretrained("BatsResearch/bonito-v1")
|
11 |
+
tokenizer = AutoTokenizer.from_pretrained("BatsResearch/bonito-v1")
|
12 |
+
model.to("cuda")
|
13 |
|
14 |
@spaces.GPU
|
15 |
def respond(
|
|
|
23 |
input_text = "<|tasktype|>\n" + task_type.strip()
|
24 |
input_text += "\n<|context|>\n" + message.strip() + "\n<|task|>\n"
|
25 |
|
26 |
+
input_ids = tokenizer.encode(input_text, return_tensors="pt").to("cuda")
|
27 |
+
output = model.generate(
|
28 |
+
input_ids,
|
29 |
+
max_new_tokens=max_tokens,
|
30 |
+
temperature=temperature,
|
31 |
+
top_p=top_p,
|
32 |
+
do_sample=True,
|
33 |
+
)
|
34 |
+
|
35 |
+
response = tokenizer.decode(output[0], skip_special_tokens=True)
|
36 |
+
|
37 |
+
# response = client.text_generation(input_text, max_new_tokens=max_tokens, temperature=temperature, top_p=top_p)
|
38 |
|
39 |
return response
|
40 |
# messages = []
|