Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,14 @@
|
|
1 |
import gradio as gr
|
2 |
-
from
|
|
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
""
|
7 |
-
|
|
|
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:
|
@@ -24,24 +18,15 @@ def respond(
|
|
24 |
messages.append({"role": "assistant", "content": val[1]})
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
-
response
|
29 |
-
|
30 |
-
for message in client.chat_completion(
|
31 |
-
messages,
|
32 |
-
max_tokens=max_tokens,
|
33 |
-
stream=True,
|
34 |
-
temperature=temperature,
|
35 |
-
top_p=top_p,
|
36 |
-
):
|
37 |
-
token = message.choices[0].delta.content
|
38 |
|
39 |
-
response += token
|
40 |
-
yield response
|
41 |
-
|
42 |
-
"""
|
43 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
44 |
-
"""
|
45 |
demo = gr.ChatInterface(
|
46 |
respond,
|
47 |
additional_inputs=[
|
@@ -58,6 +43,5 @@ demo = gr.ChatInterface(
|
|
58 |
],
|
59 |
)
|
60 |
|
61 |
-
|
62 |
if __name__ == "__main__":
|
63 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
3 |
+
from peft import PeftModel, PeftConfig
|
4 |
|
5 |
+
# Load the PEFT configuration, base model, and tokenizer
|
6 |
+
config = PeftConfig.from_pretrained("SahilCarterr/Llama-2-7B-Chat-PEFT")
|
7 |
+
base_model = AutoModelForCausalLM.from_pretrained("TheBloke/Llama-2-7b-Chat-GPTQ", device_map='auto')
|
8 |
+
model = PeftModel.from_pretrained(base_model, "SahilCarterr/Llama-2-7B-Chat-PEFT")
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained("SahilCarterr/Llama-2-7B-Chat-PEFT")
|
10 |
|
11 |
+
def respond(message, history, system_message, max_tokens, temperature, top_p):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
messages = [{"role": "system", "content": system_message}]
|
13 |
|
14 |
for val in history:
|
|
|
18 |
messages.append({"role": "assistant", "content": val[1]})
|
19 |
|
20 |
messages.append({"role": "user", "content": message})
|
21 |
+
|
22 |
+
# Encode the input
|
23 |
+
inputs = tokenizer(message, return_tensors="pt").input_ids.to('cuda')
|
24 |
+
# Generate the response using the model
|
25 |
+
outputs = model.generate(inputs, max_new_tokens=max_tokens, do_sample=True, temperature=temperature, top_p=top_p)
|
26 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
27 |
|
28 |
+
yield response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
demo = gr.ChatInterface(
|
31 |
respond,
|
32 |
additional_inputs=[
|
|
|
43 |
],
|
44 |
)
|
45 |
|
|
|
46 |
if __name__ == "__main__":
|
47 |
demo.launch()
|