askbyte commited on
Commit
ca3173f
·
verified ·
1 Parent(s): 214501d

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +98 -81
index.html CHANGED
@@ -1,83 +1,100 @@
1
- <!DOCTYPE html>
2
- <html lang="es">
3
- <head>
4
- <meta charset="UTF-8">
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>BITER API - Hugging Face Space</title>
7
- <style>
8
- body {
9
- font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
10
- max-width: 800px;
11
- margin: 0 auto;
12
- padding: 20px;
13
- line-height: 1.6;
14
- color: #333;
15
- }
16
- h1 {
17
- color: #1a1a1a;
18
- border-bottom: 2px solid #eee;
19
- padding-bottom: 10px;
20
- }
21
- .card {
22
- background: #f9f9f9;
23
- border-radius: 8px;
24
- padding: 20px;
25
- margin: 20px 0;
26
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
27
- }
28
- code {
29
- background: #eee;
30
- padding: 2px 5px;
31
- border-radius: 3px;
32
- font-family: monospace;
33
- }
34
- .endpoint {
35
- background: #e9f5ff;
36
- border-left: 4px solid #0070f3;
37
- }
38
- </style>
39
- </head>
40
- <body>
41
- <h1>BITER - API de Asistente IA para Emprendedores</h1>
42
-
43
- <div class="card">
44
- <h2>Estado del Servicio</h2>
45
- <p>✅ API activa y funcionando</p>
46
- <p>Modelo: Zephyr-7B</p>
47
- </div>
48
-
49
- <div class="card endpoint">
50
- <h2>Endpoint de la API</h2>
51
- <p>URL: <code>POST /generate</code></p>
52
- <p>Formato de solicitud:</p>
53
- <pre><code>{
54
- "message": "Tu pregunta sobre emprendimiento aquí"
55
- }</code></pre>
56
- <p>Formato de respuesta:</p>
57
- <pre><code>{
58
- "response": "Respuesta generada por BITER"
59
- }</code></pre>
60
- </div>
61
-
62
- <div class="card">
63
- <h2>Integración con tu Web</h2>
64
- <p>Para integrar BITER en justbyte.es, usa este código en tu archivo chat.php:</p>
65
- <pre><code>// Ejemplo de código para enviar solicitud a la API
66
- fetch('https://tu-usuario-huggingface.hf.space/generate', {
67
- method: 'POST',
68
- headers: {
69
- 'Content-Type': 'application/json',
70
- },
71
- body: JSON.stringify({
72
- message: preguntaDelUsuario
73
- })
74
  })
75
- .then(response => response.json())
76
- .then(data => {
77
- // Mostrar la respuesta en tu interfaz
78
- mostrarRespuesta(data.response);
79
- });</code></pre>
80
- </div>
81
- </body>
82
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
 
1
+ /**
2
+ * Ejemplo de código para integrar BITER en justbyte.es
3
+ * Este archivo muestra cómo implementar la comunicación con la API de BITER
4
+ * desde tu sitio web.
5
+ */
6
+
7
+ // URL de tu Hugging Face Space
8
+ const BITER_API_URL = "https://tu-usuario-huggingface.hf.space/generate"
9
+
10
+ // Elementos del DOM
11
+ const chatForm = document.getElementById("chat-form")
12
+ const userInput = document.getElementById("user-input")
13
+ const chatMessages = document.getElementById("chat-messages")
14
+ const loadingIndicator = document.getElementById("loading-indicator")
15
+
16
+ // Manejar envío del formulario
17
+ chatForm.addEventListener("submit", async (e) => {
18
+ e.preventDefault()
19
+
20
+ // Obtener mensaje del usuario
21
+ const userMessage = userInput.value.trim()
22
+ if (!userMessage) return
23
+
24
+ // Limpiar input
25
+ userInput.value = ""
26
+
27
+ // Mostrar mensaje del usuario
28
+ appendMessage("user", userMessage)
29
+
30
+ // Mostrar indicador de carga
31
+ loadingIndicator.style.display = "block"
32
+
33
+ try {
34
+ // Enviar solicitud a la API de BITER
35
+ const response = await fetch(BITER_API_URL, {
36
+ method: "POST",
37
+ headers: {
38
+ "Content-Type": "application/json",
39
+ },
40
+ body: JSON.stringify({
41
+ message: userMessage,
42
+ }),
43
+ })
44
+
45
+ // Verificar si la respuesta es exitosa
46
+ if (!response.ok) {
47
+ throw new Error("Error en la respuesta de la API")
48
+ }
49
+
50
+ // Obtener datos de la respuesta
51
+ const data = await response.json()
52
+
53
+ // Mostrar respuesta de BITER
54
+ appendMessage("assistant", data.response)
55
+ } catch (error) {
56
+ console.error("Error:", error)
57
+ appendMessage(
58
+ "system",
59
+ "Lo siento, ha ocurrido un error al conectar con BITER. Por favor, intenta de nuevo más tarde.",
60
+ )
61
+ } finally {
62
+ // Ocultar indicador de carga
63
+ loadingIndicator.style.display = "none"
64
+ }
 
 
 
 
 
 
 
 
 
65
  })
66
+
67
+ // Función para añadir mensajes al chat
68
+ function appendMessage(role, content) {
69
+ const messageDiv = document.createElement("div")
70
+ messageDiv.className = `message ${role}-message`
71
+
72
+ // Crear avatar
73
+ const avatar = document.createElement("div")
74
+ avatar.className = "avatar"
75
+
76
+ // Icono según el rol
77
+ if (role === "user") {
78
+ avatar.innerHTML = "👤"
79
+ } else if (role === "assistant") {
80
+ avatar.innerHTML = "🤖"
81
+ } else {
82
+ avatar.innerHTML = "⚠️"
83
+ }
84
+
85
+ // Crear contenido del mensaje
86
+ const messageContent = document.createElement("div")
87
+ messageContent.className = "message-content"
88
+ messageContent.textContent = content
89
+
90
+ // Añadir elementos al mensaje
91
+ messageDiv.appendChild(avatar)
92
+ messageDiv.appendChild(messageContent)
93
+
94
+ // Añadir mensaje al contenedor
95
+ chatMessages.appendChild(messageDiv)
96
+
97
+ // Scroll al último mensaje
98
+ chatMessages.scrollTop = chatMessages.scrollHeight
99
+ }
100