guilhermemfbastos commited on
Commit
ec00454
·
verified ·
1 Parent(s): 562c7cb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -43
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 seu ecossistema RWS
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: 250px;
19
- height: 250px;
20
  display: flex;
21
  align-items: center;
22
  justify-content: center;
23
  }
24
  """
25
 
26
- def responder_vocal(audio_path, texto_manual):
27
- # CORREÇÃO: Se você digitou, ele usa o seu texto. Se não, ele tenta ver o áudio.
28
- mensagem = texto_manual if texto_manual else "Oi"
 
29
 
30
- # Se você mandou áudio, por enquanto ele avisa (até ativarmos o STT real)
31
- if audio_path and not texto_manual:
32
- mensagem = "O usuário mandou um áudio."
 
 
33
 
34
- headers = {
35
- "Authorization": f"Bearer {TOKEN_RWS}",
36
- "Content-Type": "application/json"
37
- }
38
 
39
- try:
40
- # Envia para a Renata Evolution de verdade!
41
- response = requests.post(API_URL_RWS, headers=headers, json={"mensagem": mensagem}, timeout=60)
42
-
43
- if response.status_code == 200:
44
- texto_da_renata = response.json().get("resposta", "Não recebi resposta do núcleo.")
45
-
46
- # Gera a voz da Francisca
47
- tts = gTTS(text=texto_da_renata, lang='pt', tld='com.br')
48
- arquivo_audio = "voz_renata.mp3"
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: 50px;'>🎙️</div>")
65
 
66
- input_txt = gr.Textbox(label="Digite seu comando", placeholder="Ex: Quem é o presidente?")
67
- input_voz = gr.Audio(sources=["microphone"], type="filepath", label="Ou fale com a Renata")
68
- btn = gr.Button("ENVIAR", variant="primary")
69
 
70
- output_txt = gr.Textbox(label="Renata diz:", interactive=False)
71
- output_aud = gr.Audio(autoplay=True, visible=False)
72
 
73
  with gr.Tab("⏰ Alarmes"):
74
- gr.Dataframe(headers=["Hora", "Nome", "Ativo"], value=[["07:00", "Acordar", "Sim"]])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
 
76
- btn.click(fn=responder_vocal, inputs=[input_voz, input_txt], outputs=[output_txt, output_aud])
 
 
 
77
 
78
- demo.launch(css=ALEXA_CSS, ssr_mode=False)
 
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)