Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,24 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
#
|
| 5 |
client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct")
|
| 6 |
|
| 7 |
-
SYSTEM_PROMPT =
|
| 8 |
-
Você é JuriX,
|
| 9 |
-
Responda sempre com
|
| 10 |
-
|
| 11 |
|
| 12 |
def chat_fn(message, history):
|
| 13 |
if history is None:
|
| 14 |
history = []
|
| 15 |
|
| 16 |
-
# Monta
|
| 17 |
msgs = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 18 |
|
| 19 |
-
for
|
| 20 |
-
msgs.append({"role": "user", "content":
|
| 21 |
-
msgs.append({"role": "assistant", "content":
|
| 22 |
|
| 23 |
msgs.append({"role": "user", "content": message})
|
| 24 |
|
|
@@ -29,20 +29,19 @@ def chat_fn(message, history):
|
|
| 29 |
temperature=0.4
|
| 30 |
)
|
| 31 |
|
| 32 |
-
|
|
|
|
| 33 |
|
| 34 |
-
# Atualiza o histórico
|
| 35 |
-
history.append((message, bot_msg))
|
| 36 |
return "", history
|
| 37 |
|
| 38 |
|
| 39 |
-
with gr.Blocks(
|
| 40 |
gr.Markdown("# ⚖️ JuriX — Assistente Jurídico Profissional")
|
| 41 |
-
gr.Markdown("
|
| 42 |
|
| 43 |
chatbot = gr.Chatbot()
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
|
| 48 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# Cliente do modelo
|
| 5 |
client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct")
|
| 6 |
|
| 7 |
+
SYSTEM_PROMPT = (
|
| 8 |
+
"Você é JuriX, um assistente jurídico formal, profissional e técnico. "
|
| 9 |
+
"Responda sempre com precisão e clareza."
|
| 10 |
+
)
|
| 11 |
|
| 12 |
def chat_fn(message, history):
|
| 13 |
if history is None:
|
| 14 |
history = []
|
| 15 |
|
| 16 |
+
# Monta mensagens
|
| 17 |
msgs = [{"role": "system", "content": SYSTEM_PROMPT}]
|
| 18 |
|
| 19 |
+
for user_msg, bot_msg in history:
|
| 20 |
+
msgs.append({"role": "user", "content": user_msg})
|
| 21 |
+
msgs.append({"role": "assistant", "content": bot_msg})
|
| 22 |
|
| 23 |
msgs.append({"role": "user", "content": message})
|
| 24 |
|
|
|
|
| 29 |
temperature=0.4
|
| 30 |
)
|
| 31 |
|
| 32 |
+
bot_reply = response.choices[0].message["content"]
|
| 33 |
+
history.append((message, bot_reply))
|
| 34 |
|
|
|
|
|
|
|
| 35 |
return "", history
|
| 36 |
|
| 37 |
|
| 38 |
+
with gr.Blocks() as demo:
|
| 39 |
gr.Markdown("# ⚖️ JuriX — Assistente Jurídico Profissional")
|
| 40 |
+
gr.Markdown("Olá! Sou a JuriX e estou aqui para ajudar.")
|
| 41 |
|
| 42 |
chatbot = gr.Chatbot()
|
| 43 |
+
text = gr.Textbox(label="Digite sua mensagem e pressione ENTER")
|
| 44 |
|
| 45 |
+
text.submit(chat_fn, [text, chatbot], [text, chatbot])
|
| 46 |
|
| 47 |
+
demo.launch()
|