Spaces:
Build error

houerbot / app.py
pchernic2's picture
Update app.py
69fb909 verified
Raw History Blame Contribute Delete
2.82 kB
import gradio as gr
from huggingface_hub import InferenceClient
import os
# === 1. TOKEN DO HUGGING FACE ===
hf_token = os.environ.get("HUGGINGFACE_API_TOKEN")
client = InferenceClient("mistralai/Mistral-7B-Instruct-v0.2", token=hf_token)
# === 2. MENSAGEM SISTÊMICA ===
system_message = """
Você é um assistente que responde ÚNICA E EXCLUSIVAMENTE em português BRASILEIRO, especializado em dados sociais, de economia, finanças, gestão pública e dados demográficos do Brasil.
Baseie suas respostas em fontes como IBGE, SIDRA, BACEN e FGV Municípios. Seja objetivo e confiável.
"""
# === 3. FUNÇÃO DE RESPOSTA DO CHAT ===
def respond(message, history):
messages = [{"role": "system", "content": system_message}]
for user, assistant in history:
messages.append({"role": "user", "content": user})
messages.append({"role": "assistant", "content": assistant})
messages.append({"role": "user", "content": message})
response = ""
for message in client.chat_completion(
messages,
max_tokens=1024,
temperature=0.7,
top_p=0.95,
stream=True,
):
token = message.choices[0].delta.content
response += token
yield response
# === 4. INTERFACE VISUAL COM A PALETA HOUER ===
with gr.Blocks(
css="""
body {
background-color: #0A192F;
color: #F5F5F5;
font-family: 'Segoe UI', sans-serif;
}
.gradio-container {
background-color: #0A192F !important;
}
.gr-chatbot {
background-color: #112240 !important;
}
.gr-button {
background-color: #1F6FEB !important;
color: white !important;
border-radius: 8px !important;
}
.gr-button:hover {
background-color: #388BFF !important;
}
.gr-textbox textarea {
background-color: #F5F5F5 !important;
color: #333333 !important;
border-radius: 6px;
}
"""
) as demo:
# === LOGO HOUER ===
gr.Image(
value="https://lirp.cdn-website.com/62692e45/dms3rep/multi/opt/Manual+de+marca+-+Houer+-+2020+%281%29+%282%29+BRANCA-1920w.png",
height=200,
show_label=False,
container=False
)
# === CHAT ===
gr.ChatInterface(
fn=respond,
title="Houer | Inteligência em Dados Públicos",
description="Pergunte sobre indicadores sociais, econômicos e demográficos do Brasil. Exemplo: 'Qual o desemprego em Minas Gerais?'",
theme="soft",
submit_btn="Consultar",
stop_btn="Parar",
chatbot=gr.Chatbot(
height=800) # ou mais, conforme necessário
)
# === 5. EXECUÇÃO ===
if __name__ == "__main__":
demo.launch(share=True)