Spaces:
Running
Running
File size: 1,172 Bytes
8725491 5d08654 8725491 5d08654 8725491 80cd37d 8725491 80cd37d 5d08654 8725491 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
import spaces
from transformers import pipeline
import gradio as gr
pipe = pipeline('text-generation', model=model, tokenizer=tokenizer, device='cuda:0')
INSTRUCTION_KEY = "### Instruction:"
RESPONSE_KEY = "### Response:"
INTRO_BLURB = "Below is an instruction that describes a task. Write a response that appropriately completes the request."
PROMPT_FOR_GENERATION_FORMAT = """{intro}
{instruction_key}
{instruction}
{response_key}
""".format(
intro=INTRO_BLURB,
instruction_key=INSTRUCTION_KEY,
instruction="{instruction}",
response_key=RESPONSE_KEY,
)
example = "James decides to run 3 sprints 3 times a week. He runs 60 meters each sprint. How many total meters does he run a week? Explain before answering."
fmt_ex = PROMPT_FOR_GENERATION_FORMAT.format(instruction=example)
@spaces.GPU
def run():
with torch.autocast('cuda', dtype=torch.bfloat16):
return(
pipe('Here is a recipe for vegan banana bread:\n',
max_new_tokens=100,
do_sample=True,
use_cache=True))
with gr.Blocks() as app:
btn = gr.Button()
outp=gr.Textbox()
btn.click(run,None,outp)
app.launch()
|