VikaskumarDas commited on
Commit
c71e464
·
verified ·
1 Parent(s): 437c93b

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +5 -10
script.js CHANGED
@@ -82,6 +82,7 @@ function useSuggestion(text) {
82
  sendMessage();
83
  }
84
 
 
85
  async function sendMessage() {
86
  const input = document.getElementById('userInput');
87
  const text = input.value.trim();
@@ -92,11 +93,9 @@ async function sendMessage() {
92
  conversations[currentChatId] = { title: text.substring(0, 24), messages: [] };
93
  }
94
 
95
- // স্ক্রিন পরিবর্তন
96
  document.getElementById('welcomeScreen').style.display = 'none';
97
  document.getElementById('chatMessages').style.display = 'flex';
98
 
99
- // ইউজার মেসেজ রেন্ডার ও সেভ
100
  appendBubble('user', text);
101
  conversations[currentChatId].messages.push({ role: 'user', text: text });
102
 
@@ -108,21 +107,19 @@ async function sendMessage() {
108
  saveToLocalStorage();
109
  renderHistory();
110
 
111
- // লোডিং ইন্ডিকেটর শো করা
112
  appendBubble('bot', 'Thinking...');
113
  const lastBubble = document.getElementById('chatMessages').lastChild.querySelector('.bubble-text');
114
 
115
  try {
116
- // সরাসরি Gradio /predict endpoint োস্ট রিোয়েস্ট ঠানো
117
- const response = await fetch("/call/predict", {
118
  method: "POST",
119
  headers: { "Content-Type": "application/json" },
120
- body: JSON.stringify({ data: [text] })
121
  });
122
  const resJson = await response.json();
123
- const reply = resJson.data[0];
124
 
125
- // লোডিং টেক্সট সরিয়ে বটের আসল উত্তর বসানো
126
  lastBubble.innerText = reply;
127
  conversations[currentChatId].messages.push({ role: 'bot', text: reply });
128
  saveToLocalStorage();
@@ -139,9 +136,7 @@ function saveToLocalStorage() {
139
  localStorage.setItem('gemini_history', JSON.stringify(conversations));
140
  }
141
 
142
- // ইনিশিয়াল লোড
143
  setTimeout(() => {
144
  renderHistory();
145
- // মোবাইল স্ক্রিনে ডিফল্ট সাইডবার বন্ধ রাখা
146
  if(window.innerWidth <= 768) document.getElementById('sidebar').classList.add('closed');
147
  }, 300);
 
82
  sendMessage();
83
  }
84
 
85
+ // এই ফাংশনটি FastAPI-র সাথে কানেক্ট করার জন্য আপডেট করা হলো
86
  async function sendMessage() {
87
  const input = document.getElementById('userInput');
88
  const text = input.value.trim();
 
93
  conversations[currentChatId] = { title: text.substring(0, 24), messages: [] };
94
  }
95
 
 
96
  document.getElementById('welcomeScreen').style.display = 'none';
97
  document.getElementById('chatMessages').style.display = 'flex';
98
 
 
99
  appendBubble('user', text);
100
  conversations[currentChatId].messages.push({ role: 'user', text: text });
101
 
 
107
  saveToLocalStorage();
108
  renderHistory();
109
 
 
110
  appendBubble('bot', 'Thinking...');
111
  const lastBubble = document.getElementById('chatMessages').lastChild.querySelector('.bubble-text');
112
 
113
  try {
114
+ // নতুন FastAPIন্ডয়েন্ট ক কর হচ্ছে
115
+ const response = await fetch("/api/chat", {
116
  method: "POST",
117
  headers: { "Content-Type": "application/json" },
118
+ body: JSON.stringify({ message: text })
119
  });
120
  const resJson = await response.json();
121
+ const reply = resJson.reply;
122
 
 
123
  lastBubble.innerText = reply;
124
  conversations[currentChatId].messages.push({ role: 'bot', text: reply });
125
  saveToLocalStorage();
 
136
  localStorage.setItem('gemini_history', JSON.stringify(conversations));
137
  }
138
 
 
139
  setTimeout(() => {
140
  renderHistory();
 
141
  if(window.innerWidth <= 768) document.getElementById('sidebar').classList.add('closed');
142
  }, 300);