Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
AGENTE_JSON = """
|
| 9 |
{
|
|
@@ -36,31 +40,37 @@ AGENTE_JSON = """
|
|
| 36 |
}
|
| 37 |
"""
|
| 38 |
|
| 39 |
-
def
|
| 40 |
return f"""
|
| 41 |
-
|
| 42 |
|
| 43 |
### AGENTE ###
|
| 44 |
{AGENTE_JSON}
|
| 45 |
|
| 46 |
### MENSAGEM DO USUÁRIO ###
|
| 47 |
-
{
|
| 48 |
|
| 49 |
-
|
| 50 |
-
Responda como o Indeniza AI, seguindo exatamente o JSON acima.
|
| 51 |
"""
|
| 52 |
|
| 53 |
-
def responder(mensagem):
|
| 54 |
-
prompt =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
result = client.
|
| 57 |
-
|
| 58 |
-
|
| 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 |
-
|
| 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()
|