Abmacode12 commited on
Commit
cbaa149
·
verified ·
1 Parent(s): a0ae92e

Nous avons bien intégré l’interface sur Hugging Face, mais une erreur apparaît dans le chat de Rosalinda :

Browse files

Unexpected token '<'


Cela vient du fait que le frontend appelle une URL locale (localhost:3000) mais le backend n’est pas accessible publiquement.

✅ Solution technique à mettre en place :

Déployer le backend Node.js sur une plateforme gratuite comme :

🔗 https://render.com
(recommandé)
ou
🔗 https://railway.app

Une fois le backend déployé, remplacer dans script.js :

fetch("http://localhost:3000/chat", ...)


par :

fetch("https://rosalinda-backend.onrender.com/chat", ...)


Même chose pour /image et /whisper si on utilise la génération d’images ou la saisie vocale.

Files changed (1) hide show
  1. script.js +16 -7
script.js CHANGED
@@ -1,8 +1,8 @@
1
 
2
- // Configuration Backend
3
  const BACKEND_URL = window.location.hostname === 'localhost'
4
  ? "http://localhost:3000"
5
- : window.location.origin;
6
  let isRecording = false;
7
  let mediaRecorder;
8
  let audioChunks = [];
@@ -27,8 +27,11 @@ async function sendMessage() {
27
  chatInput.value = '';
28
  activityMonitor.textContent = '[ Rosalinda réfléchit... ]';
29
 
 
 
 
30
  try {
31
- const response = await fetch(`${BACKEND_URL}/api/chat`, {
32
  method: 'POST',
33
  headers: {
34
  'Content-Type': 'application/json'
@@ -99,12 +102,12 @@ async function toggleRecording() {
99
  activityMonitor.textContent = '[ Traitement audio... ]';
100
  }
101
  }
102
-
103
  async function sendAudioMessage(audioBlob) {
104
  try {
105
  const formData = new FormData();
106
  formData.append('audio', audioBlob, 'recording.wav');
107
- const response = await fetch(`${BACKEND_URL}/api/whisper`, {
 
108
  method: 'POST',
109
  body: formData
110
  });
@@ -127,7 +130,8 @@ document.querySelector('.menu button:nth-child(1)').addEventListener('click', as
127
  if (prompt) {
128
  try {
129
  activityMonitor.textContent = '[ Génération image en cours... ]';
130
- const response = await fetch(`${BACKEND_URL}/api/image`, {
 
131
  method: 'POST',
132
  headers: {
133
  'Content-Type': 'application/json'
@@ -152,4 +156,9 @@ method: 'POST',
152
  }
153
  }
154
  });
155
- console.log("Interface Espace Codage connectée au backend complet.");
 
 
 
 
 
 
1
 
2
+ // Configuration Backend - Auto-detect environment
3
  const BACKEND_URL = window.location.hostname === 'localhost'
4
  ? "http://localhost:3000"
5
+ : "https://rosalinda-backend.onrender.com"; // Replace with your actual Render/Railway URL
6
  let isRecording = false;
7
  let mediaRecorder;
8
  let audioChunks = [];
 
27
  chatInput.value = '';
28
  activityMonitor.textContent = '[ Rosalinda réfléchit... ]';
29
 
30
+ // Check if we're on Hugging Face Spaces
31
+ const isHuggingFace = window.location.hostname.includes('hf.space');
32
+
33
  try {
34
+ const response = await fetch(`${isHuggingFace ? 'https://rosalinda-backend.onrender.com' : BACKEND_URL}/api/chat`, {
35
  method: 'POST',
36
  headers: {
37
  'Content-Type': 'application/json'
 
102
  activityMonitor.textContent = '[ Traitement audio... ]';
103
  }
104
  }
 
105
  async function sendAudioMessage(audioBlob) {
106
  try {
107
  const formData = new FormData();
108
  formData.append('audio', audioBlob, 'recording.wav');
109
+ const isHuggingFace = window.location.hostname.includes('hf.space');
110
+ const response = await fetch(`${isHuggingFace ? 'https://rosalinda-backend.onrender.com' : BACKEND_URL}/api/whisper`, {
111
  method: 'POST',
112
  body: formData
113
  });
 
130
  if (prompt) {
131
  try {
132
  activityMonitor.textContent = '[ Génération image en cours... ]';
133
+ const isHuggingFace = window.location.hostname.includes('hf.space');
134
+ const response = await fetch(`${isHuggingFace ? 'https://rosalinda-backend.onrender.com' : BACKEND_URL}/api/image`, {
135
  method: 'POST',
136
  headers: {
137
  'Content-Type': 'application/json'
 
156
  }
157
  }
158
  });
159
+ // Detect environment and log appropriate message
160
+ if (window.location.hostname.includes('hf.space')) {
161
+ console.log("Interface Espace Codage connectée au backend de production sur Render");
162
+ } else {
163
+ console.log("Interface Espace Codage connectée au backend local");
164
+ }