Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,10 @@
|
|
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("bushai/sar-i-7b")
|
8 |
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def respond(
|
11 |
message,
|
@@ -16,7 +15,7 @@ def respond(
|
|
16 |
top_p,
|
17 |
):
|
18 |
messages = [{"role": "system", "content": system_message}]
|
19 |
-
|
20 |
for val in history:
|
21 |
if val[0]:
|
22 |
messages.append({"role": "user", "content": val[0]})
|
@@ -25,24 +24,13 @@ def respond(
|
|
25 |
|
26 |
messages.append({"role": "user", "content": message})
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
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 |
-
|
40 |
-
yield response
|
41 |
|
42 |
-
|
43 |
-
"""
|
44 |
-
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
45 |
-
"""
|
46 |
demo = gr.ChatInterface(
|
47 |
respond,
|
48 |
additional_inputs=[
|
@@ -59,6 +47,5 @@ demo = gr.ChatInterface(
|
|
59 |
],
|
60 |
)
|
61 |
|
62 |
-
|
63 |
if __name__ == "__main__":
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Cargar el modelo y el tokenizer directamente
|
5 |
+
model_name = "bushai/sar-i-7b"
|
6 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
7 |
+
model = AutoModelForCausalLM.from_pretrained(model_name)
|
8 |
|
9 |
def respond(
|
10 |
message,
|
|
|
15 |
top_p,
|
16 |
):
|
17 |
messages = [{"role": "system", "content": system_message}]
|
18 |
+
|
19 |
for val in history:
|
20 |
if val[0]:
|
21 |
messages.append({"role": "user", "content": val[0]})
|
|
|
24 |
|
25 |
messages.append({"role": "user", "content": message})
|
26 |
|
27 |
+
inputs = tokenizer(message, return_tensors="pt")
|
28 |
+
outputs = model.generate(inputs['input_ids'], max_new_tokens=max_tokens, temperature=temperature, top_p=top_p)
|
29 |
+
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
|
31 |
+
return response
|
|
|
32 |
|
33 |
+
# Configurar la interfaz de Gradio
|
|
|
|
|
|
|
34 |
demo = gr.ChatInterface(
|
35 |
respond,
|
36 |
additional_inputs=[
|
|
|
47 |
],
|
48 |
)
|
49 |
|
|
|
50 |
if __name__ == "__main__":
|
51 |
demo.launch()
|