studycode129 commited on
Commit
21b5630
·
verified ·
1 Parent(s): 2d142a7

Create app.js

Browse files
Files changed (1) hide show
  1. app.js +60 -0
app.js ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const results = [];
2
+ const key = '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'; // replace this with your actual key
3
+
4
+ document.getElementById('fileUpload').addEventListener('change', async function () {
5
+ const file = this.files[0];
6
+ const fileNameDisplay = document.getElementById('fileName');
7
+ fileNameDisplay.textContent = file ? file.name : 'No file selected';
8
+ if (!file) return;
9
+
10
+ const text = await file.text();
11
+ const prompts = text.split(/\r?\n/).filter(Boolean);
12
+ document.getElementById('loading').style.display = 'block';
13
+
14
+ for (const prompt of prompts) {
15
+ await send(prompt);
16
+ }
17
+
18
+ document.getElementById('loading').style.display = 'none';
19
+ });
20
+
21
+ async function send(overridePrompt) {
22
+ const model = document.getElementById("model").value;
23
+ const prompt = overridePrompt || document.getElementById("prompt").value;
24
+ if (!prompt) return;
25
+
26
+ document.getElementById('loading').style.display = 'block';
27
+
28
+ const res = await fetch("https://openrouter.ai/api/v1/chat/completions", {
29
+ method: "POST",
30
+ headers: {
31
+ "Authorization": "Bearer " + key,
32
+ "Content-Type": "application/json",
33
+ "HTTP-Referer": "https://huggingface.co/spaces/studycode129/Free_Web_LLM_Tester"
34
+ },
35
+ body: JSON.stringify({
36
+ model,
37
+ messages: [{ role: "user", content: prompt }],
38
+ temperature: 0.7
39
+ })
40
+ });
41
+
42
+ const data = await res.json();
43
+ const output = data.choices?.[0]?.message?.content || JSON.stringify(data);
44
+ document.getElementById("response").textContent = output;
45
+
46
+ results.push({ model, prompt, output });
47
+ document.getElementById('loading').style.display = 'none';
48
+ }
49
+
50
+ function downloadCSV() {
51
+ let csv = "Model,Prompt,Output\n";
52
+ results.forEach(row => {
53
+ csv += `"${row.model}","${row.prompt.replace(/\n/g, " ")}","${row.output.replace(/\n/g, " ")}"\n`;
54
+ });
55
+ const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
56
+ const link = document.createElement("a");
57
+ link.href = URL.createObjectURL(blob);
58
+ link.download = "llm_test_results.csv";
59
+ link.click();
60
+ }