Spaces:
Sleeping
Sleeping
UI and functionality done
Browse files
app.py
CHANGED
|
@@ -1,18 +1,12 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from huggingface_hub import InferenceClient
|
| 3 |
-
#from unsloth import FastLanguageModel
|
| 4 |
from peft import AutoPeftModelForCausalLM
|
| 5 |
from transformers import AutoTokenizer
|
| 6 |
|
| 7 |
-
|
| 8 |
"""
|
| 9 |
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
|
| 10 |
"""
|
| 11 |
-
#client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
| 12 |
-
#client = InferenceClient("halme/id2223_lora_model")
|
| 13 |
-
|
| 14 |
|
| 15 |
-
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature,
|
| 16 |
messages = [{"role": "system", "content": system_message}]
|
| 17 |
|
| 18 |
for val in history:
|
|
@@ -23,32 +17,10 @@ def respond(message, history: list[tuple[str, str]], system_message, max_tokens,
|
|
| 23 |
|
| 24 |
messages.append({"role": "user", "content": message})
|
| 25 |
|
| 26 |
-
#response = ""
|
| 27 |
-
|
| 28 |
-
""" for message in client.chat_completion(messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p):
|
| 29 |
-
token = message.choices[0].delta.content
|
| 30 |
-
|
| 31 |
-
response += token
|
| 32 |
-
yield response """
|
| 33 |
-
|
| 34 |
-
""" model, tokenizer = FastLanguageModel.from_pretrained(
|
| 35 |
-
model_name = "halme/id2223_lora_model", # YOUR MODEL YOU USED FOR TRAINING
|
| 36 |
-
max_seq_length = max_tokens,
|
| 37 |
-
dtype = None,
|
| 38 |
-
load_in_4bit = True,
|
| 39 |
-
) """
|
| 40 |
-
|
| 41 |
model = AutoPeftModelForCausalLM.from_pretrained(
|
| 42 |
"halme/id2223_lora_model", # YOUR MODEL YOU USED FOR TRAINING
|
| 43 |
)
|
| 44 |
-
tokenizer = AutoTokenizer.from_pretrained("halme/id2223_lora_model")
|
| 45 |
-
|
| 46 |
-
#FastLanguageModel.for_inference(model) # Enable native 2x faster inference
|
| 47 |
-
|
| 48 |
-
"""messages = [
|
| 49 |
-
{"role": "user", "content": "Continue the fibonnaci sequence: 1, 1, 2, 3, 5, 8,"},
|
| 50 |
-
] """
|
| 51 |
-
|
| 52 |
inputs = tokenizer.apply_chat_template(
|
| 53 |
messages,
|
| 54 |
tokenize = True,
|
|
@@ -56,12 +28,12 @@ def respond(message, history: list[tuple[str, str]], system_message, max_tokens,
|
|
| 56 |
return_tensors = "pt",
|
| 57 |
)
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
use_cache = True, temperature = 1.5, min_p = 0.1)
|
| 64 |
|
|
|
|
| 65 |
|
| 66 |
"""
|
| 67 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
@@ -70,14 +42,14 @@ demo = gr.ChatInterface(
|
|
| 70 |
respond,
|
| 71 |
additional_inputs=[
|
| 72 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 73 |
-
gr.Slider(minimum=1, maximum=2048, value=
|
| 74 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=
|
| 75 |
gr.Slider(
|
| 76 |
minimum=0.1,
|
| 77 |
maximum=1.0,
|
| 78 |
-
value=0.
|
| 79 |
-
step=0.
|
| 80 |
-
label="
|
| 81 |
),
|
| 82 |
],
|
| 83 |
)
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
from peft import AutoPeftModelForCausalLM
|
| 3 |
from transformers import AutoTokenizer
|
| 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 |
|
| 9 |
+
def respond(message, history: list[tuple[str, str]], system_message, max_tokens, temperature, min_p,):
|
| 10 |
messages = [{"role": "system", "content": system_message}]
|
| 11 |
|
| 12 |
for val in history:
|
|
|
|
| 17 |
|
| 18 |
messages.append({"role": "user", "content": message})
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
model = AutoPeftModelForCausalLM.from_pretrained(
|
| 21 |
"halme/id2223_lora_model", # YOUR MODEL YOU USED FOR TRAINING
|
| 22 |
)
|
| 23 |
+
tokenizer = AutoTokenizer.from_pretrained("halme/id2223_lora_model")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
inputs = tokenizer.apply_chat_template(
|
| 25 |
messages,
|
| 26 |
tokenize = True,
|
|
|
|
| 28 |
return_tensors = "pt",
|
| 29 |
)
|
| 30 |
|
| 31 |
+
output = model.generate(input_ids = inputs, max_new_tokens = max_tokens,
|
| 32 |
+
use_cache = True, temperature = temperature, min_p = min_p)
|
| 33 |
+
|
| 34 |
+
response = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
|
|
|
|
| 35 |
|
| 36 |
+
yield response.split('assistant')[-1]
|
| 37 |
|
| 38 |
"""
|
| 39 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
|
| 42 |
respond,
|
| 43 |
additional_inputs=[
|
| 44 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
| 45 |
+
gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
|
| 46 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=1.5, step=0.1, label="Temperature"),
|
| 47 |
gr.Slider(
|
| 48 |
minimum=0.1,
|
| 49 |
maximum=1.0,
|
| 50 |
+
value=0.99,
|
| 51 |
+
step=0.01,
|
| 52 |
+
label="Min-p",
|
| 53 |
),
|
| 54 |
],
|
| 55 |
)
|