Update script.js
Browse files
script.js
CHANGED
|
@@ -1,156 +1,40 @@
|
|
| 1 |
-
|
| 2 |
|
| 3 |
-
|
| 4 |
-
"image",
|
| 5 |
-
"draw",
|
| 6 |
-
"paint",
|
| 7 |
-
"picture",
|
| 8 |
-
"photo",
|
| 9 |
-
"art",
|
| 10 |
-
"illustration",
|
| 11 |
-
"generate image"
|
| 12 |
-
],
|
| 13 |
|
| 14 |
-
|
| 15 |
-
"translate",
|
| 16 |
-
"translation",
|
| 17 |
-
"convert language"
|
| 18 |
-
],
|
| 19 |
|
| 20 |
-
|
| 21 |
-
"summarize",
|
| 22 |
-
"summary",
|
| 23 |
-
"shorten"
|
| 24 |
-
],
|
| 25 |
-
|
| 26 |
-
code: [
|
| 27 |
-
"code",
|
| 28 |
-
"python",
|
| 29 |
-
"java",
|
| 30 |
-
"cpp",
|
| 31 |
-
"c++",
|
| 32 |
-
"program"
|
| 33 |
-
],
|
| 34 |
-
|
| 35 |
-
speech: [
|
| 36 |
-
"speech",
|
| 37 |
-
"voice",
|
| 38 |
-
"audio"
|
| 39 |
-
],
|
| 40 |
-
|
| 41 |
-
ocr: [
|
| 42 |
-
"ocr",
|
| 43 |
-
"scan",
|
| 44 |
-
"extract text"
|
| 45 |
-
],
|
| 46 |
-
|
| 47 |
-
caption: [
|
| 48 |
-
"caption",
|
| 49 |
-
"describe image"
|
| 50 |
-
]
|
| 51 |
-
|
| 52 |
-
};
|
| 53 |
-
|
| 54 |
-
function detectModel(prompt){
|
| 55 |
-
|
| 56 |
-
prompt = prompt.toLowerCase();
|
| 57 |
-
|
| 58 |
-
for(let task in keywords){
|
| 59 |
-
|
| 60 |
-
for(let word of keywords[task]){
|
| 61 |
-
|
| 62 |
-
if(prompt.includes(word)){
|
| 63 |
-
|
| 64 |
-
return task;
|
| 65 |
-
|
| 66 |
-
}
|
| 67 |
-
|
| 68 |
-
}
|
| 69 |
|
|
|
|
|
|
|
| 70 |
}
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
document.getElementById("generateBtn").onclick=function(){
|
| 77 |
-
|
| 78 |
-
const prompt=document.getElementById("prompt").value;
|
| 79 |
-
|
| 80 |
-
const task=detectModel(prompt);
|
| 81 |
-
|
| 82 |
-
let model="";
|
| 83 |
-
|
| 84 |
-
let output="";
|
| 85 |
-
|
| 86 |
-
switch(task){
|
| 87 |
-
|
| 88 |
-
case "image":
|
| 89 |
-
|
| 90 |
-
model="Stable Diffusion XL";
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
-
|
| 95 |
|
| 96 |
-
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
-
output
|
|
|
|
| 101 |
|
| 102 |
-
|
| 103 |
|
| 104 |
-
|
|
|
|
| 105 |
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
output="📄 Summarization Model Selected";
|
| 109 |
-
|
| 110 |
-
break;
|
| 111 |
-
|
| 112 |
-
case "code":
|
| 113 |
-
|
| 114 |
-
model="Code Llama";
|
| 115 |
-
|
| 116 |
-
output="💻 Code Generation Model Selected";
|
| 117 |
-
|
| 118 |
-
break;
|
| 119 |
-
|
| 120 |
-
case "speech":
|
| 121 |
-
|
| 122 |
-
model="Whisper";
|
| 123 |
-
|
| 124 |
-
output="🎤 Speech Recognition Model Selected";
|
| 125 |
-
|
| 126 |
-
break;
|
| 127 |
-
|
| 128 |
-
case "ocr":
|
| 129 |
-
|
| 130 |
-
model="TrOCR";
|
| 131 |
-
|
| 132 |
-
output="📷 OCR Model Selected";
|
| 133 |
-
|
| 134 |
-
break;
|
| 135 |
-
|
| 136 |
-
case "caption":
|
| 137 |
-
|
| 138 |
-
model="BLIP";
|
| 139 |
-
|
| 140 |
-
output="🖼 Image Captioning Model Selected";
|
| 141 |
-
|
| 142 |
-
break;
|
| 143 |
-
|
| 144 |
-
default:
|
| 145 |
|
| 146 |
-
|
| 147 |
|
| 148 |
-
|
|
|
|
| 149 |
|
| 150 |
}
|
| 151 |
|
| 152 |
-
document.getElementById("model").innerHTML=model;
|
| 153 |
-
|
| 154 |
-
document.getElementById("output").innerHTML=output;
|
| 155 |
-
|
| 156 |
}
|
|
|
|
| 1 |
+
document.getElementById("generateBtn").onclick = async function(){
|
| 2 |
|
| 3 |
+
const prompt = document.getElementById("prompt").value;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
const task = detectTask(prompt);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
let modelName = MODELS[task];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
if(!modelName){
|
| 10 |
+
modelName = MODELS.text;
|
| 11 |
}
|
| 12 |
|
| 13 |
+
document.getElementById("model").innerHTML = modelName;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
document.getElementById("output").innerHTML = "Generating...";
|
| 16 |
|
| 17 |
+
const result = await queryHF(modelName,prompt);
|
| 18 |
|
| 19 |
+
if(Array.isArray(result)){
|
| 20 |
|
| 21 |
+
if(result[0].generated_text){
|
| 22 |
|
| 23 |
+
document.getElementById("output").innerHTML =
|
| 24 |
+
result[0].generated_text;
|
| 25 |
|
| 26 |
+
}else{
|
| 27 |
|
| 28 |
+
document.getElementById("output").innerHTML =
|
| 29 |
+
JSON.stringify(result);
|
| 30 |
|
| 31 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
}else{
|
| 34 |
|
| 35 |
+
document.getElementById("output").innerHTML =
|
| 36 |
+
JSON.stringify(result,null,2);
|
| 37 |
|
| 38 |
}
|
| 39 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
}
|