Spaces:
Runtime error
Runtime error
Nihal Nayak
commited on
Commit
·
e1ae004
1
Parent(s):
716cf6a
min example
Browse files- app.py +25 -26
- requirements.txt +2 -2
app.py
CHANGED
|
@@ -1,44 +1,42 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
-
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
# import spaces
|
| 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 |
|
| 13 |
# move to cuda
|
| 14 |
-
model.to("cuda")
|
| 15 |
|
| 16 |
def respond(
|
| 17 |
context: str,
|
| 18 |
-
task_type: str,
|
| 19 |
-
max_tokens: int = 256,
|
| 20 |
-
temperature: float = 0.5,
|
| 21 |
-
top_p: float = 0.95,
|
| 22 |
):
|
| 23 |
-
task_type = "extractive question answering"
|
| 24 |
-
input_text = "<|tasktype|>\n" + task_type.strip()
|
| 25 |
-
input_text += (
|
| 26 |
-
"\n<|context|>\n" + context.strip() + "\n<|task|>\n"
|
| 27 |
-
)
|
| 28 |
-
|
| 29 |
-
input_ids = tokenizer.encode(input_text, return_tensors="pt").to("cuda")
|
| 30 |
-
outputs = model.generate(
|
| 31 |
-
input_ids,
|
| 32 |
-
max_new_tokens=max_tokens,
|
| 33 |
-
temperature=temperature,
|
| 34 |
-
do_sample=True,
|
| 35 |
-
top_p=top_p,
|
| 36 |
-
)
|
| 37 |
-
pred_start = int(input_ids.shape[-1])
|
| 38 |
-
pred = tokenizer.decode(outputs[pred_start:], skip_special_tokens=True)
|
| 39 |
|
| 40 |
-
# replace the context
|
| 41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
return pred
|
| 43 |
|
| 44 |
|
|
@@ -87,7 +85,8 @@ examples = [
|
|
| 87 |
|
| 88 |
demo = gr.Interface(
|
| 89 |
respond,
|
| 90 |
-
inputs=[gr.Textbox(lines=5, label="Enter context here"), gr.Dropdown(["extractive question answering"], label="Task Type")],
|
|
|
|
| 91 |
outputs=gr.Textbox(lines=20, label="Generated Instruction-Response Pairs"),
|
| 92 |
additional_inputs=[
|
| 93 |
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
+
# from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 4 |
# import spaces
|
| 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 |
|
| 13 |
# move to cuda
|
| 14 |
+
# model.to("cuda")
|
| 15 |
|
| 16 |
def respond(
|
| 17 |
context: str,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
| 20 |
|
| 21 |
+
# task_type = "extractive question answering"
|
| 22 |
+
# input_text = "<|tasktype|>\n" + task_type.strip()
|
| 23 |
+
# input_text += (
|
| 24 |
+
# "\n<|context|>\n" + context.strip() + "\n<|task|>\n"
|
| 25 |
+
# )
|
| 26 |
+
|
| 27 |
+
# input_ids = tokenizer.encode(input_text, return_tensors="pt").to("cuda")
|
| 28 |
+
# outputs = model.generate(
|
| 29 |
+
# input_ids,
|
| 30 |
+
# max_new_tokens=max_tokens,
|
| 31 |
+
# temperature=temperature,
|
| 32 |
+
# do_sample=True,
|
| 33 |
+
# top_p=top_p,
|
| 34 |
+
# )
|
| 35 |
+
# pred_start = int(input_ids.shape[-1])
|
| 36 |
+
# pred = tokenizer.decode(outputs[pred_start:], skip_special_tokens=True)
|
| 37 |
+
|
| 38 |
+
# replace the context
|
| 39 |
+
pred = ""
|
| 40 |
return pred
|
| 41 |
|
| 42 |
|
|
|
|
| 85 |
|
| 86 |
demo = gr.Interface(
|
| 87 |
respond,
|
| 88 |
+
# inputs=[gr.Textbox(lines=5, label="Enter context here"), gr.Dropdown(["extractive question answering"], label="Task Type")],
|
| 89 |
+
inputs=gr.Textbox(lines=5, label="Enter context here"),
|
| 90 |
outputs=gr.Textbox(lines=20, label="Generated Instruction-Response Pairs"),
|
| 91 |
additional_inputs=[
|
| 92 |
# gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
requirements.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
huggingface_hub==0.22.2
|
| 2 |
-
transformers
|
| 3 |
-
accelerate
|
|
|
|
| 1 |
huggingface_hub==0.22.2
|
| 2 |
+
# transformers
|
| 3 |
+
# accelerate
|