Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import openai
|
| 3 |
+
import requests
|
| 4 |
+
|
| 5 |
+
# Configuraci贸n de la interfaz
|
| 6 |
+
st.set_page_config(page_title="Boti Asistente", layout="wide", initial_sidebar_state="expanded")
|
| 7 |
+
|
| 8 |
+
# Funciones de OpenAI
|
| 9 |
+
openai.api_key = 'YOUR_OPENAI_API_KEY'
|
| 10 |
+
|
| 11 |
+
def obtener_respuesta(prompt):
|
| 12 |
+
response = openai.Completion.create(
|
| 13 |
+
engine="davinci",
|
| 14 |
+
prompt=prompt,
|
| 15 |
+
max_tokens=150
|
| 16 |
+
)
|
| 17 |
+
return response.choices[0].text.strip()
|
| 18 |
+
|
| 19 |
+
# Estilos personalizados
|
| 20 |
+
st.markdown(
|
| 21 |
+
"""
|
| 22 |
+
<style>
|
| 23 |
+
.sidebar .sidebar-content {
|
| 24 |
+
background-color: #2C3E50;
|
| 25 |
+
}
|
| 26 |
+
.sidebar .sidebar-content .element-container {
|
| 27 |
+
color: #ECF0F1;
|
| 28 |
+
}
|
| 29 |
+
.main {
|
| 30 |
+
background-color: #ECF0F1;
|
| 31 |
+
}
|
| 32 |
+
</style>
|
| 33 |
+
""",
|
| 34 |
+
unsafe_allow_html=True
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Funciones para las p谩ginas
|
| 38 |
+
def pagina_principal():
|
| 39 |
+
st.title("Bienvenido a Boti Asistente")
|
| 40 |
+
st.write("Esta es la p谩gina principal de Boti Asistente, especializado en el desarrollo de bots para Botidinamics.")
|
| 41 |
+
|
| 42 |
+
def pagina_asistente():
|
| 43 |
+
st.title("Asistente Boti")
|
| 44 |
+
st.write("Pregunta algo a Boti Asistente:")
|
| 45 |
+
pregunta = st.text_input("Tu pregunta:")
|
| 46 |
+
|
| 47 |
+
if st.button("Enviar"):
|
| 48 |
+
respuesta = obtener_respuesta(pregunta)
|
| 49 |
+
st.write(f"Boti Asistente: {respuesta}")
|
| 50 |
+
|
| 51 |
+
st.markdown(
|
| 52 |
+
"""
|
| 53 |
+
<button onclick="startRecording()">
|
| 54 |
+
<img src='https://www.iconfinder.com/data/icons/google-material-design-3-0/48/ic_keyboard_voice_48px-512.png' alt='icon' width='20' height='20'/>
|
| 55 |
+
Capturar Voz
|
| 56 |
+
</button>
|
| 57 |
+
<script>
|
| 58 |
+
function startRecording() {
|
| 59 |
+
const recognition = new (window.SpeechRecognition || window.webkitSpeechRecognition)();
|
| 60 |
+
recognition.lang = 'es-ES';
|
| 61 |
+
recognition.interimResults = false;
|
| 62 |
+
recognition.maxAlternatives = 1;
|
| 63 |
+
recognition.start();
|
| 64 |
+
recognition.onresult = (event) => {
|
| 65 |
+
const lastResult = event.results.length - 1;
|
| 66 |
+
const text = event.results[lastResult][0].transcript;
|
| 67 |
+
document.querySelector("input[name='unique_chat_input_key']").value = text;
|
| 68 |
+
};
|
| 69 |
+
recognition.onspeechend = () => {
|
| 70 |
+
recognition.stop();
|
| 71 |
+
};
|
| 72 |
+
recognition.onerror = (event) => {
|
| 73 |
+
console.error(event.error);
|
| 74 |
+
};
|
| 75 |
+
}
|
| 76 |
+
</script>
|
| 77 |
+
""",
|
| 78 |
+
unsafe_allow_html=True
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
def pagina_agentes():
|
| 82 |
+
st.title("Agentes")
|
| 83 |
+
st.write("Aqu铆 puedes gestionar y desarrollar m煤ltiples agentes para tus proyectos.")
|
| 84 |
+
|
| 85 |
+
# Barra de navegaci贸n lateral
|
| 86 |
+
st.sidebar.title("Boti Asistente - Botidinamics")
|
| 87 |
+
st.sidebar.markdown("Seleccione una opci贸n:")
|
| 88 |
+
opciones = ["P谩gina Principal", "Asistente Boti", "Agentes"]
|
| 89 |
+
seleccion = st.sidebar.selectbox("Opciones", opciones)
|
| 90 |
+
|
| 91 |
+
if seleccion == "P谩gina Principal":
|
| 92 |
+
pagina_principal()
|
| 93 |
+
elif seleccion == "Asistente Boti":
|
| 94 |
+
pagina_asistente()
|
| 95 |
+
elif seleccion == "Agentes":
|
| 96 |
+
pagina_agentes()
|