Spaces:
Runtime error
Runtime error
add some comments
Browse files- frontend/src/lib/App.svelte +10 -1
frontend/src/lib/App.svelte
CHANGED
@@ -40,6 +40,7 @@
|
|
40 |
null;
|
41 |
}
|
42 |
|
|
|
43 |
function newChat() {
|
44 |
const chatId = nanoid();
|
45 |
const chat: Chat = {
|
@@ -55,6 +56,9 @@
|
|
55 |
$chatsStore = $chatsStore.filter((chat) => chat.id !== id);
|
56 |
}
|
57 |
|
|
|
|
|
|
|
58 |
function submitMessage(event: CustomEvent) {
|
59 |
if ($chatsStore.length === 0) {
|
60 |
newChat();
|
@@ -89,6 +93,7 @@
|
|
89 |
runInference($lastBase64Image, content);
|
90 |
}
|
91 |
}
|
|
|
92 |
function updateChatStore(message: Message) {
|
93 |
$chatsStore = $chatsStore.map((chat) => {
|
94 |
if (chat.id === $selectedChatId) {
|
@@ -97,7 +102,7 @@
|
|
97 |
return chat;
|
98 |
});
|
99 |
}
|
100 |
-
|
101 |
async function runInference(image: string, prompt: string) {
|
102 |
if (isLoading || image === '' || prompt === '') {
|
103 |
return;
|
@@ -156,6 +161,10 @@
|
|
156 |
case 'process_generating':
|
157 |
$loadingState = data.success ? 'Generating' : 'Error';
|
158 |
break;
|
|
|
|
|
|
|
|
|
159 |
case 'process_completed':
|
160 |
try {
|
161 |
const response = data.output as InferenceResponse;
|
|
|
40 |
null;
|
41 |
}
|
42 |
|
43 |
+
// this is when page starts or user deletes all chats
|
44 |
function newChat() {
|
45 |
const chatId = nanoid();
|
46 |
const chat: Chat = {
|
|
|
56 |
$chatsStore = $chatsStore.filter((chat) => chat.id !== id);
|
57 |
}
|
58 |
|
59 |
+
// this is called when user send a text or image
|
60 |
+
// if image then update last image store
|
61 |
+
// if text and has image send to inference
|
62 |
function submitMessage(event: CustomEvent) {
|
63 |
if ($chatsStore.length === 0) {
|
64 |
newChat();
|
|
|
93 |
runInference($lastBase64Image, content);
|
94 |
}
|
95 |
}
|
96 |
+
// hack to update store
|
97 |
function updateChatStore(message: Message) {
|
98 |
$chatsStore = $chatsStore.map((chat) => {
|
99 |
if (chat.id === $selectedChatId) {
|
|
|
102 |
return chat;
|
103 |
});
|
104 |
}
|
105 |
+
// run inference via websockets
|
106 |
async function runInference(image: string, prompt: string) {
|
107 |
if (isLoading || image === '' || prompt === '') {
|
108 |
return;
|
|
|
161 |
case 'process_generating':
|
162 |
$loadingState = data.success ? 'Generating' : 'Error';
|
163 |
break;
|
164 |
+
|
165 |
+
// here is success
|
166 |
+
// got an image in response from inference
|
167 |
+
// then update the chat store
|
168 |
case 'process_completed':
|
169 |
try {
|
170 |
const response = data.output as InferenceResponse;
|