Spaces:
Running
Running
as
Browse files
app.py
CHANGED
@@ -1,8 +1,7 @@
|
|
1 |
-
import gradio as gr
|
2 |
import json
|
3 |
from datetime import datetime
|
|
|
4 |
from huggingface_hub import InferenceClient
|
5 |
-
|
6 |
now = datetime.now()
|
7 |
|
8 |
# Carregar configurações
|
@@ -13,13 +12,16 @@ client = InferenceClient(
|
|
13 |
model="meta-llama/Llama-3.2-3B-Instruct"
|
14 |
)
|
15 |
|
16 |
-
|
|
|
17 |
# INFORMAÇÕES GERAIS: (hoje é {now.strftime("%d/%m/%Y %H:%M:%S")},
|
18 |
# VOCÊ FOI CRIADO PELO GRUPO Last, O SEU NOME É 'GUI',
|
19 |
# ESTAS SÃO SUAS CONFIGURAÇÕES E REGRAS: {config},
|
20 |
# SUAS RESPOSTAS DEVEM SER SARCASTICAMENTE DIVERTIDAS :),
|
21 |
"""
|
22 |
|
|
|
|
|
23 |
def respond(
|
24 |
message,
|
25 |
history: list[tuple[str, str]],
|
@@ -28,7 +30,6 @@ def respond(
|
|
28 |
temperature,
|
29 |
top_p,
|
30 |
):
|
31 |
-
# Formatação das mensagens conforme o novo padrão
|
32 |
messages = [{"role": "system", "content": system_message}]
|
33 |
|
34 |
for val in history:
|
@@ -41,7 +42,6 @@ def respond(
|
|
41 |
|
42 |
response = ""
|
43 |
|
44 |
-
# Chamada para o cliente de chat usando o novo formato
|
45 |
for message in client.chat_completion(
|
46 |
messages,
|
47 |
max_tokens=max_tokens,
|
@@ -50,20 +50,31 @@ def respond(
|
|
50 |
top_p=top_p,
|
51 |
):
|
52 |
token = message.choices[0].delta.content
|
|
|
53 |
response += token
|
54 |
yield response
|
55 |
|
56 |
-
|
|
|
|
|
|
|
57 |
demo = gr.ChatInterface(
|
58 |
-
|
59 |
-
|
60 |
-
gr.Textbox(value=
|
61 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
62 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
63 |
-
gr.Slider(
|
|
|
|
|
|
|
|
|
|
|
|
|
64 |
],
|
65 |
-
type="messages"
|
66 |
)
|
67 |
|
|
|
68 |
if __name__ == "__main__":
|
69 |
demo.launch()
|
|
|
|
|
|
1 |
import json
|
2 |
from datetime import datetime
|
3 |
+
import gradio as gr
|
4 |
from huggingface_hub import InferenceClient
|
|
|
5 |
now = datetime.now()
|
6 |
|
7 |
# Carregar configurações
|
|
|
12 |
model="meta-llama/Llama-3.2-3B-Instruct"
|
13 |
)
|
14 |
|
15 |
+
|
16 |
+
rules_gui = f"""
|
17 |
# INFORMAÇÕES GERAIS: (hoje é {now.strftime("%d/%m/%Y %H:%M:%S")},
|
18 |
# VOCÊ FOI CRIADO PELO GRUPO Last, O SEU NOME É 'GUI',
|
19 |
# ESTAS SÃO SUAS CONFIGURAÇÕES E REGRAS: {config},
|
20 |
# SUAS RESPOSTAS DEVEM SER SARCASTICAMENTE DIVERTIDAS :),
|
21 |
"""
|
22 |
|
23 |
+
|
24 |
+
|
25 |
def respond(
|
26 |
message,
|
27 |
history: list[tuple[str, str]],
|
|
|
30 |
temperature,
|
31 |
top_p,
|
32 |
):
|
|
|
33 |
messages = [{"role": "system", "content": system_message}]
|
34 |
|
35 |
for val in history:
|
|
|
42 |
|
43 |
response = ""
|
44 |
|
|
|
45 |
for message in client.chat_completion(
|
46 |
messages,
|
47 |
max_tokens=max_tokens,
|
|
|
50 |
top_p=top_p,
|
51 |
):
|
52 |
token = message.choices[0].delta.content
|
53 |
+
|
54 |
response += token
|
55 |
yield response
|
56 |
|
57 |
+
|
58 |
+
"""
|
59 |
+
For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
|
60 |
+
"""
|
61 |
demo = gr.ChatInterface(
|
62 |
+
respond,
|
63 |
+
additional_inputs=[
|
64 |
+
gr.Textbox(value=rules_gui, label="System message"),
|
65 |
gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
|
66 |
gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
|
67 |
+
gr.Slider(
|
68 |
+
minimum=0.1,
|
69 |
+
maximum=1.0,
|
70 |
+
value=0.95,
|
71 |
+
step=0.05,
|
72 |
+
label="Top-p (nucleus sampling)",
|
73 |
+
),
|
74 |
],
|
|
|
75 |
)
|
76 |
|
77 |
+
|
78 |
if __name__ == "__main__":
|
79 |
demo.launch()
|
80 |
+
|