Spaces:
Runtime error
Runtime error
flydust
commited on
Commit
·
15d1015
1
Parent(s):
b02961f
update model info
Browse files
README.md
CHANGED
|
@@ -8,6 +8,6 @@ sdk_version: 4.36.1
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: llama3
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: llama3
|
| 11 |
+
models:
|
| 12 |
+
- Magpie-Align/Llama-3-8B-Magpie-Align-v0.1
|
| 13 |
+
---
|
app.py
CHANGED
|
@@ -1,19 +1,27 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
|
|
|
| 10 |
def respond(
|
| 11 |
message,
|
| 12 |
history: list[tuple[str, str]],
|
| 13 |
system_message,
|
| 14 |
-
max_tokens,
|
| 15 |
-
temperature,
|
| 16 |
-
top_p,
|
|
|
|
| 17 |
):
|
| 18 |
messages = [{"role": "system", "content": system_message}]
|
| 19 |
|
|
@@ -24,20 +32,27 @@ def respond(
|
|
| 24 |
messages.append({"role": "assistant", "content": val[1]})
|
| 25 |
|
| 26 |
messages.append({"role": "user", "content": message})
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
for message in client.chat_completion(
|
| 31 |
messages,
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
|
| 42 |
"""
|
| 43 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
@@ -45,19 +60,20 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
|
|
| 45 |
demo = gr.ChatInterface(
|
| 46 |
respond,
|
| 47 |
additional_inputs=[
|
| 48 |
-
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 49 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 50 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=0.
|
| 51 |
gr.Slider(
|
| 52 |
minimum=0.1,
|
| 53 |
maximum=1.0,
|
| 54 |
-
value=0.
|
| 55 |
step=0.05,
|
| 56 |
label="Top-p (nucleus sampling)",
|
| 57 |
),
|
|
|
|
| 58 |
],
|
| 59 |
)
|
| 60 |
|
| 61 |
|
| 62 |
if __name__ == "__main__":
|
| 63 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 3 |
+
import spaces
|
| 4 |
|
| 5 |
+
# Load model and tokenizer
|
| 6 |
+
model_name = "Magpie-Align/Llama-3-8B-Magpie-Align-v0.1"
|
|
|
|
|
|
|
| 7 |
|
| 8 |
+
device = "cuda" # the device to load the model onto
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 11 |
+
model_name,
|
| 12 |
+
torch_dtype="auto"
|
| 13 |
+
)
|
| 14 |
+
model.to(device)
|
| 15 |
|
| 16 |
+
@spaces.GPU(enable_queue=True)
|
| 17 |
def respond(
|
| 18 |
message,
|
| 19 |
history: list[tuple[str, str]],
|
| 20 |
system_message,
|
| 21 |
+
max_tokens=2048,
|
| 22 |
+
temperature=0.6,
|
| 23 |
+
top_p=0.9,
|
| 24 |
+
repetition_penalty=1.0,
|
| 25 |
):
|
| 26 |
messages = [{"role": "system", "content": system_message}]
|
| 27 |
|
|
|
|
| 32 |
messages.append({"role": "assistant", "content": val[1]})
|
| 33 |
|
| 34 |
messages.append({"role": "user", "content": message})
|
| 35 |
+
|
| 36 |
+
text = tokenizer.apply_chat_template(
|
|
|
|
|
|
|
| 37 |
messages,
|
| 38 |
+
tokenize=False,
|
| 39 |
+
add_generation_prompt=True
|
| 40 |
+
)
|
| 41 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(device)
|
| 42 |
+
|
| 43 |
+
generated_ids = model.generate(
|
| 44 |
+
model_inputs.input_ids,
|
| 45 |
+
max_new_tokens = max_tokens,
|
| 46 |
+
temperature = temperature,
|
| 47 |
+
top_p = top_p,
|
| 48 |
+
repetition_penalty=repetition_penalty,
|
| 49 |
+
)
|
| 50 |
+
generated_ids = [
|
| 51 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 52 |
+
]
|
| 53 |
|
| 54 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 55 |
+
return response
|
| 56 |
|
| 57 |
"""
|
| 58 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
|
| 60 |
demo = gr.ChatInterface(
|
| 61 |
respond,
|
| 62 |
additional_inputs=[
|
| 63 |
+
gr.Textbox(value="You are Magpie, a friendly Chatbot.", label="System message"),
|
| 64 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
| 65 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=0.6, step=0.1, label="Temperature"),
|
| 66 |
gr.Slider(
|
| 67 |
minimum=0.1,
|
| 68 |
maximum=1.0,
|
| 69 |
+
value=0.9,
|
| 70 |
step=0.05,
|
| 71 |
label="Top-p (nucleus sampling)",
|
| 72 |
),
|
| 73 |
+
gr.Slider(minimum=0.5, maximum=1.5, value=1.0, step=0.1, label="Repetation Penalty"),
|
| 74 |
],
|
| 75 |
)
|
| 76 |
|
| 77 |
|
| 78 |
if __name__ == "__main__":
|
| 79 |
+
demo.launch(share=True)
|