Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
"""
|
5 |
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
|
6 |
"""
|
7 |
-
client = InferenceClient("eforse01/lora_model")
|
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 |
|
20 |
for val in history:
|
@@ -25,20 +17,24 @@ def respond(
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
|
|
|
|
29 |
|
30 |
-
|
|
|
31 |
messages,
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
|
40 |
-
|
|
|
|
|
41 |
|
|
|
42 |
|
43 |
"""
|
44 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
@@ -47,18 +43,17 @@ demo = gr.ChatInterface(
|
|
47 |
respond,
|
48 |
additional_inputs=[
|
49 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
50 |
-
gr.Slider(minimum=1, maximum=2048, value=
|
51 |
-
gr.Slider(minimum=0.1, maximum=4.0, value=
|
52 |
gr.Slider(
|
53 |
minimum=0.1,
|
54 |
maximum=1.0,
|
55 |
-
value=0.
|
56 |
-
step=0.
|
57 |
-
label="
|
58 |
),
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
-
demo.launch()
|
|
|
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 |
+
"eforse01/lora_model",
|
22 |
+
)
|
23 |
|
24 |
+
tokenizer = AutoTokenizer.from_pretrained("eforse01/lora_model")
|
25 |
+
inputs = tokenizer.apply_chat_template(
|
26 |
messages,
|
27 |
+
tokenize = True,
|
28 |
+
add_generation_prompt = True,
|
29 |
+
return_tensors = "pt",
|
30 |
+
)
|
|
|
|
|
31 |
|
32 |
+
output = model.generate(input_ids = inputs, max_new_tokens = max_tokens,
|
33 |
+
use_cache = True, temperature = temperature, min_p = min_p)
|
34 |
+
|
35 |
+
response = tokenizer.batch_decode(output, skip_special_tokens=True)[0]
|
36 |
|
37 |
+
yield response.split('assistant')[-1]
|
38 |
|
39 |
"""
|
40 |
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
|
|
43 |
respond,
|
44 |
additional_inputs=[
|
45 |
gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
|
46 |
+
gr.Slider(minimum=1, maximum=2048, value=2048, step=1, label="Max new tokens"),
|
47 |
+
gr.Slider(minimum=0.1, maximum=4.0, value=1.5, step=0.1, label="Temperature"),
|
48 |
gr.Slider(
|
49 |
minimum=0.1,
|
50 |
maximum=1.0,
|
51 |
+
value=0.99,
|
52 |
+
step=0.01,
|
53 |
+
label="Min-p",
|
54 |
),
|
55 |
],
|
56 |
)
|
57 |
|
|
|
58 |
if __name__ == "__main__":
|
59 |
+
demo.launch()
|