Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,77 +2,95 @@ import gradio as gr
|
|
| 2 |
import requests
|
| 3 |
from gtts import gTTS
|
| 4 |
import os
|
|
|
|
| 5 |
|
| 6 |
-
# Configurações do
|
| 7 |
API_URL_RWS = "https://guilhermemfbastos-romaniowebservices.hf.space/v1/chat"
|
| 8 |
TOKEN_RWS = "Rws_token_22122006"
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
ALEXA_CSS = """
|
| 11 |
.gradio-container {background-color: #00050a !important; color: white !important;}
|
| 12 |
.alexa-ring {
|
| 13 |
border: 5px solid #00CAFF;
|
| 14 |
border-radius: 50%;
|
| 15 |
-
padding: 20px;
|
| 16 |
box-shadow: 0 0 20px #00CAFF;
|
| 17 |
margin: 20px auto;
|
| 18 |
-
width:
|
| 19 |
-
height:
|
| 20 |
display: flex;
|
| 21 |
align-items: center;
|
| 22 |
justify-content: center;
|
| 23 |
}
|
| 24 |
"""
|
| 25 |
|
| 26 |
-
def
|
| 27 |
-
#
|
| 28 |
-
mensagem =
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
}
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
tts.save(arquivo_audio)
|
| 50 |
-
|
| 51 |
-
return texto_da_renata, arquivo_audio
|
| 52 |
-
else:
|
| 53 |
-
return f"Erro RWS: {response.status_code}", None
|
| 54 |
-
|
| 55 |
-
except Exception as e:
|
| 56 |
-
return f"Erro de conexão: {str(e)}", None
|
| 57 |
|
| 58 |
-
with gr.Blocks() as demo:
|
| 59 |
-
gr.Markdown("<h1 style='color: #00CAFF; text-align: center;'>🔵 ROMANIO ECHO</h1>")
|
| 60 |
|
| 61 |
with gr.Tabs():
|
| 62 |
with gr.Tab("🏠 Home"):
|
| 63 |
with gr.Column(elem_classes="alexa-ring"):
|
| 64 |
-
gr.Markdown("<div style='font-size:
|
| 65 |
|
| 66 |
-
input_txt = gr.Textbox(label="
|
| 67 |
-
input_voz = gr.Audio(sources=["microphone"], type="filepath", label="
|
| 68 |
-
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
with gr.Tab("⏰ Alarmes"):
|
| 74 |
-
gr.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
demo.launch(
|
|
|
|
| 2 |
import requests
|
| 3 |
from gtts import gTTS
|
| 4 |
import os
|
| 5 |
+
from datetime import datetime
|
| 6 |
|
| 7 |
+
# Configurações do ecossistema RWS
|
| 8 |
API_URL_RWS = "https://guilhermemfbastos-romaniowebservices.hf.space/v1/chat"
|
| 9 |
TOKEN_RWS = "Rws_token_22122006"
|
| 10 |
|
| 11 |
+
# "Banco de Dados" na memória
|
| 12 |
+
banco_dados = {
|
| 13 |
+
"alarmes": [],
|
| 14 |
+
"lembretes": [],
|
| 15 |
+
"rotinas": {"Bom dia": ["Previsão do tempo", "Notícias"], "Estudar": ["Modo foco"]}
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
ALEXA_CSS = """
|
| 19 |
.gradio-container {background-color: #00050a !important; color: white !important;}
|
| 20 |
.alexa-ring {
|
| 21 |
border: 5px solid #00CAFF;
|
| 22 |
border-radius: 50%;
|
|
|
|
| 23 |
box-shadow: 0 0 20px #00CAFF;
|
| 24 |
margin: 20px auto;
|
| 25 |
+
width: 200px;
|
| 26 |
+
height: 200px;
|
| 27 |
display: flex;
|
| 28 |
align-items: center;
|
| 29 |
justify-content: center;
|
| 30 |
}
|
| 31 |
"""
|
| 32 |
|
| 33 |
+
def assistente_completo(audio, texto, aba_atual="Home"):
|
| 34 |
+
# 1. LÓGICA DE CONVERSA (RWS)
|
| 35 |
+
mensagem = texto if texto else "Oi"
|
| 36 |
+
headers = {"Authorization": f"Bearer {TOKEN_RWS}"}
|
| 37 |
|
| 38 |
+
try:
|
| 39 |
+
res = requests.post(API_URL_RWS, headers=headers, json={"mensagem": mensagem}, timeout=30)
|
| 40 |
+
resposta_texto = res.json().get("resposta", "Estou pronta.")
|
| 41 |
+
except:
|
| 42 |
+
resposta_texto = "Erro ao conectar ao RWS."
|
| 43 |
|
| 44 |
+
# 2. GERAR VOZ
|
| 45 |
+
tts = gTTS(text=resposta_texto, lang='pt', tld='com.br')
|
| 46 |
+
tts.save("resposta.mp3")
|
|
|
|
| 47 |
|
| 48 |
+
return resposta_texto, "resposta.mp3"
|
| 49 |
+
|
| 50 |
+
def adicionar_alarme(hora, nome):
|
| 51 |
+
banco_dados["alarmes"].append([hora, nome, "Ativo"])
|
| 52 |
+
return banco_dados["alarmes"]
|
| 53 |
+
|
| 54 |
+
def adicionar_lembrete(txt):
|
| 55 |
+
agora = datetime.now().strftime("%H:%M")
|
| 56 |
+
banco_dados["lembretes"].append([agora, txt])
|
| 57 |
+
return banco_dados["lembretes"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
with gr.Blocks(css=ALEXA_CSS) as demo:
|
| 60 |
+
gr.Markdown("<h1 style='color: #00CAFF; text-align: center;'>🔵 ROMANIO ECHO FULL</h1>")
|
| 61 |
|
| 62 |
with gr.Tabs():
|
| 63 |
with gr.Tab("🏠 Home"):
|
| 64 |
with gr.Column(elem_classes="alexa-ring"):
|
| 65 |
+
gr.Markdown("<div style='font-size: 80px;'>🎙️</div>")
|
| 66 |
|
| 67 |
+
input_txt = gr.Textbox(label="Comando", placeholder="Pergunte qualquer coisa...")
|
| 68 |
+
input_voz = gr.Audio(sources=["microphone"], type="filepath", label="Fale")
|
| 69 |
+
btn_talk = gr.Button("EXECUTAR", variant="primary")
|
| 70 |
|
| 71 |
+
out_txt = gr.Textbox(label="Renata diz:")
|
| 72 |
+
out_aud = gr.Audio(autoplay=True, visible=False)
|
| 73 |
|
| 74 |
with gr.Tab("⏰ Alarmes"):
|
| 75 |
+
with gr.Row():
|
| 76 |
+
in_hora = gr.Textbox(label="Hora (ex: 08:00)")
|
| 77 |
+
in_nome = gr.Textbox(label="Nome do Alarme")
|
| 78 |
+
btn_add_al = gr.Button("CONFIGURAR ALARME")
|
| 79 |
+
lista_alarmes = gr.Dataframe(headers=["Hora", "Nome", "Status"], value=banco_dados["alarmes"])
|
| 80 |
+
|
| 81 |
+
with gr.Tab("📝 Lembretes"):
|
| 82 |
+
in_lemb = gr.Textbox(label="O que devo lembrar?")
|
| 83 |
+
btn_add_lemb = gr.Button("CRIAR LEMBRETE")
|
| 84 |
+
lista_lembretes = gr.Dataframe(headers=["Hora Criado", "Lembrete"], value=banco_dados["lembretes"])
|
| 85 |
+
|
| 86 |
+
with gr.Tab("⚙️ Rotinas"):
|
| 87 |
+
gr.Markdown("### Rotinas Ativas")
|
| 88 |
+
gr.JSON(value=banco_dados["rotinas"])
|
| 89 |
+
gr.Button("EXECUTAR ROTINA 'BOM DIA'")
|
| 90 |
|
| 91 |
+
# Eventos Funcionais
|
| 92 |
+
btn_talk.click(assistente_completo, [input_voz, input_txt], [out_txt, out_aud])
|
| 93 |
+
btn_add_al.click(adicionar_alarme, [in_hora, in_nome], lista_alarmes)
|
| 94 |
+
btn_add_lemb.click(adicionar_lembrete, [in_lemb], lista_lembretes)
|
| 95 |
|
| 96 |
+
demo.launch(ssr_mode=False)
|