pedrolaskawski commited on
Commit
eaaee3f
·
verified ·
1 Parent(s): de2c1e0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -19
app.py CHANGED
@@ -3,7 +3,11 @@ import gradio as gr
3
  from huggingface_hub import InferenceClient
4
 
5
  HF_TOKEN = os.getenv("HF_TOKEN")
6
- client = InferenceClient("google/gemma-2-9b-it", token=HF_TOKEN)
 
 
 
 
7
 
8
  AGENTE_JSON = """
9
  {
@@ -36,31 +40,37 @@ AGENTE_JSON = """
36
  }
37
  """
38
 
39
- def montar_prompt(user_msg):
40
  return f"""
41
- Você deve seguir rigorosamente as instruções abaixo, que definem o comportamento do agente jurídico:
42
 
43
  ### AGENTE ###
44
  {AGENTE_JSON}
45
 
46
  ### MENSAGEM DO USUÁRIO ###
47
- {user_msg}
48
 
49
- ### SUA RESPOSTA ###
50
- Responda como o Indeniza AI, seguindo exatamente o JSON acima.
51
  """
52
 
53
- def responder(mensagem):
54
- prompt = montar_prompt(mensagem)
 
 
 
 
 
55
 
56
- result = client.text_generation(
57
- prompt,
58
- max_new_tokens=500,
59
  temperature=0.2,
60
  top_p=0.9
61
  )
62
- return result
63
 
 
 
 
64
 
65
  with gr.Blocks() as demo:
66
  gr.Markdown("## ⚖️ IndenizaAI — Assistente Jurídico Especializado")
@@ -68,11 +78,6 @@ with gr.Blocks() as demo:
68
  chat = gr.Chatbot()
69
  inp = gr.Textbox(label="Sua mensagem")
70
 
71
- def process(msg, history):
72
- output = responder(msg)
73
- history.append((msg, output))
74
- return history, ""
75
-
76
- inp.submit(process, [inp, chat], [chat, inp])
77
 
78
- demo.launch()
 
3
  from huggingface_hub import InferenceClient
4
 
5
  HF_TOKEN = os.getenv("HF_TOKEN")
6
+
7
+ client = InferenceClient(
8
+ model="google/gemma-2-9b-it",
9
+ token=HF_TOKEN
10
+ )
11
 
12
  AGENTE_JSON = """
13
  {
 
40
  }
41
  """
42
 
43
+ def montar_mensagem_usuario(msg):
44
  return f"""
45
+ Siga integralmente as instruções do JSON a seguir:
46
 
47
  ### AGENTE ###
48
  {AGENTE_JSON}
49
 
50
  ### MENSAGEM DO USUÁRIO ###
51
+ {msg}
52
 
53
+ Responda como o IndenizaAI.
 
54
  """
55
 
56
+ def responder(mensagem, historico):
57
+ prompt = montar_mensagem_usuario(mensagem)
58
+
59
+ messages = [
60
+ {"role": "system", "content": "Você é o IndenizaAI, um assistente jurídico altamente técnico."},
61
+ {"role": "user", "content": prompt}
62
+ ]
63
 
64
+ result = client.chat_completion(
65
+ messages=messages,
66
+ max_tokens=500,
67
  temperature=0.2,
68
  top_p=0.9
69
  )
 
70
 
71
+ resposta = result.choices[0].message["content"]
72
+ historico.append((mensagem, resposta))
73
+ return historico, ""
74
 
75
  with gr.Blocks() as demo:
76
  gr.Markdown("## ⚖️ IndenizaAI — Assistente Jurídico Especializado")
 
78
  chat = gr.Chatbot()
79
  inp = gr.Textbox(label="Sua mensagem")
80
 
81
+ inp.submit(responder, [inp, chat], [chat, inp])
 
 
 
 
 
82
 
83
+ demo.launch()