Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
pipe = pipeline("text-generation", model="HuggingFaceH4/zephyr-7b-beta", torch_dtype=torch.bfloat16, device_map="auto")
|
5 |
+
|
6 |
+
instruction = """
|
7 |
+
<|system|>
|
8 |
+
You are a pirate chatbot who always responds with Arr!</s>
|
9 |
+
<|user|>
|
10 |
+
"""
|
11 |
+
|
12 |
+
def infer(prompt):
|
13 |
+
prompt = instruction.format(f"{prompt} </s>")
|
14 |
+
print(f"PROMPT: {prompt}")
|
15 |
+
outputs = pipe(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)
|
16 |
+
print(outputs)
|
17 |
+
|
18 |
+
return outputs
|
19 |
+
|
20 |
+
gr.Interface(
|
21 |
+
fn = infer,
|
22 |
+
inputs = [
|
23 |
+
gr.Textbox()
|
24 |
+
],
|
25 |
+
outputs = [
|
26 |
+
gr.Textbox()
|
27 |
+
]
|
28 |
+
).queue().launch()
|