thamile commited on
Commit
af0dd60
·
verified ·
1 Parent(s): 4cb5887

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -17
app.py CHANGED
@@ -1,24 +1,24 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # Conexão com o modelo
5
  client = InferenceClient("meta-llama/Llama-3.1-8B-Instruct")
6
 
7
- SYSTEM_PROMPT = """
8
- Você é JuriX, uma IA formal, profissional e objetiva.
9
- Responda sempre com clareza, precisão e linguagem jurídica técnica.
10
- """
11
 
12
  def chat_fn(message, history):
13
  if history is None:
14
  history = []
15
 
16
- # Monta as mensagens para o modelo
17
  msgs = [{"role": "system", "content": SYSTEM_PROMPT}]
18
 
19
- for h in history:
20
- msgs.append({"role": "user", "content": h[0]})
21
- msgs.append({"role": "assistant", "content": h[1]})
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
- bot_msg = response.choices[0].message["content"]
 
33
 
34
- # Atualiza o histórico
35
- history.append((message, bot_msg))
36
  return "", history
37
 
38
 
39
- with gr.Blocks(theme="gradio/soft") as demo:
40
  gr.Markdown("# ⚖️ JuriX — Assistente Jurídico Profissional")
41
- gr.Markdown("Bem-vindo! Como posso ajudar?")
42
 
43
  chatbot = gr.Chatbot()
44
- msg = gr.Textbox(label="Digite sua mensagem")
45
 
46
- msg.submit(chat_fn, [msg, chatbot], [msg, chatbot])
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()