vinayabc1824 commited on
Commit
7b3a806
Β·
verified Β·
1 Parent(s): dc8e212

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +136 -26
templates/index.html CHANGED
@@ -1,31 +1,122 @@
1
  <!DOCTYPE html>
2
- <html lang="en" class="h-full bg-gradient-to-br from-purple-500 to-indigo-600">
3
  <head>
4
  <meta charset="UTF-8" />
5
- <title>✨ Flan-T5 Playground</title>
 
6
  <script src="https://cdn.tailwindcss.com"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  </head>
8
- <body class="h-full flex items-center justify-center">
9
- <div class="bg-white bg-opacity-90 backdrop-blur-md rounded-3xl shadow-xl p-10 w-full max-w-xl text-center">
10
- <h1 class="text-3xl font-bold mb-4 text-indigo-700">🧠 Flan-T5 Playground</h1>
11
- <p class="text-gray-700 mb-6">Paste your prompt and optional context below. See how the AI judges it!</p>
12
- <textarea id="prompt" rows="4" class="w-full border border-gray-300 rounded-xl p-4 focus:outline-none focus:ring-2 focus:ring-indigo-500 mb-4" placeholder="Your prompt..."></textarea>
13
- <textarea id="context" rows="2" class="w-full border border-gray-300 rounded-xl p-4 focus:outline-none focus:ring-2 focus:ring-indigo-500 mb-4" placeholder="Optional context..."></textarea>
14
- <button id="generateBtn" class="bg-indigo-600 hover:bg-indigo-700 text-white font-bold py-3 px-6 rounded-full shadow-md transition-all">Generate ✨</button>
15
- <div id="result" class="mt-6 text-left text-gray-800 whitespace-pre-wrap break-words"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  </div>
17
-
18
  <script>
19
- const generateBtn = document.getElementById('generateBtn');
20
- const resultDiv = document.getElementById('result');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- generateBtn.onclick = async () => {
 
 
 
 
 
 
 
 
 
 
23
  const prompt = document.getElementById('prompt').value.trim();
24
  const context = document.getElementById('context').value.trim();
25
-
26
  if (!prompt) return alert("Please enter a prompt!");
27
-
28
- resultDiv.innerHTML = "⏳ Generating...";
 
29
  try {
30
  const response = await fetch("/generate", {
31
  method: "POST",
@@ -34,30 +125,49 @@
34
  });
35
  const data = await response.json();
36
  const raw = data.response || "❌ No response";
37
-
38
  // Parse sections
39
  const scoresMatch = raw.match(/Scores:\s*(.*?)\s*Comments:/s);
40
  const commentsMatch = raw.match(/Comments:\s*(.*?)\s*Suggested:/s);
41
  const suggestedMatch = raw.match(/Suggested:\s*(.*)/s);
42
-
43
- let html = "";
44
  if (scoresMatch) {
45
  const scores = scoresMatch[1].split(",").map(s => s.trim()).join("<br>");
46
- html += `<h3 class="text-lg font-bold mb-1">πŸ“Š Scores</h3><p class="mb-4">${scores}</p>`;
 
 
47
  }
48
  if (commentsMatch) {
49
  const comments = commentsMatch[1].split(",").map(s => s.trim()).join("<br>");
50
- html += `<h3 class="text-lg font-bold mb-1">πŸ’¬ Comments</h3><p class="mb-4">${comments}</p>`;
 
 
51
  }
52
  if (suggestedMatch) {
53
- html += `<h3 class="text-lg font-bold mb-1">✏️ Suggested Prompt</h3><blockquote class="p-4 bg-gray-100 rounded-xl">${suggestedMatch[1].trim()}</blockquote>`;
 
 
54
  }
 
 
 
 
 
 
 
 
55
 
56
- resultDiv.innerHTML = html || "❌ Could not parse output!";
 
 
 
 
 
 
 
 
57
  } catch (err) {
58
- resultDiv.innerHTML = "❌ Error: " + err;
59
  }
60
  };
61
  </script>
62
  </body>
63
- </html>
 
1
  <!DOCTYPE html>
2
+ <html lang="en" class="h-full">
3
  <head>
4
  <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>✨ AI Prompt Auditor</title>
7
  <script src="https://cdn.tailwindcss.com"></script>
8
+ <script>
9
+ tailwind.config = {
10
+ darkMode: 'class',
11
+ theme: {
12
+ extend: {
13
+ colors: {
14
+ primary: '#6366f1',
15
+ accent: '#a5b4fc',
16
+ bgLight: '#f3f4f6',
17
+ bgDark: '#18181b',
18
+ },
19
+ },
20
+ },
21
+ }
22
+ </script>
23
  </head>
24
+ <body class="h-full bg-bgLight dark:bg-bgDark transition-colors duration-300">
25
+ <div class="min-h-screen flex flex-col items-center justify-center px-4 py-8">
26
+ <div class="w-full max-w-2xl bg-white dark:bg-zinc-900 bg-opacity-90 dark:bg-opacity-90 rounded-3xl shadow-2xl p-8 md:p-12 transition-colors duration-300">
27
+ <div class="flex items-center justify-between mb-6">
28
+ <h1 class="text-3xl md:text-4xl font-extrabold text-primary dark:text-accent flex items-center gap-2">
29
+ <span>🧠</span> AI Prompt Auditor
30
+ </h1>
31
+ <button id="toggleTheme" aria-label="Toggle dark mode" class="rounded-full p-2 bg-zinc-200 dark:bg-zinc-700 hover:bg-zinc-300 dark:hover:bg-zinc-600 transition-colors">
32
+ <svg id="themeIcon" xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 text-primary dark:text-accent" fill="none" viewBox="0 0 24 24" stroke="currentColor">
33
+ <path id="sunIcon" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 3v1m0 16v1m8.66-13.66l-.71.71M4.05 19.07l-.71.71M21 12h-1M4 12H3m16.66 5.66l-.71-.71M4.05 4.93l-.71-.71M12 7a5 5 0 100 10 5 5 0 000-10z" />
34
+ <path id="moonIcon" class="hidden" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12.79A9 9 0 1111.21 3a7 7 0 109.79 9.79z" />
35
+ </svg>
36
+ </button>
37
+ </div>
38
+ <p class="text-zinc-700 dark:text-zinc-300 mb-2">Paste your prompt and optional context below. See how the AI judges it!</p>
39
+ <p class="text-xs text-zinc-500 dark:text-zinc-400 mb-6">πŸ’‘ Try prompts like: <span class="italic">"Write a detailed Python script that fetches weather data..."</span></p>
40
+ <form id="promptForm" class="space-y-4">
41
+ <textarea id="prompt" rows="4" class="w-full border border-zinc-300 dark:border-zinc-700 rounded-xl p-4 focus:outline-none focus:ring-2 focus:ring-primary dark:bg-zinc-800 dark:text-zinc-100 transition-colors" placeholder="Your prompt..." required></textarea>
42
+ <textarea id="context" rows="2" class="w-full border border-zinc-300 dark:border-zinc-700 rounded-xl p-4 focus:outline-none focus:ring-2 focus:ring-primary dark:bg-zinc-800 dark:text-zinc-100 transition-colors" placeholder="Optional context..."></textarea>
43
+ <div class="flex gap-4 justify-center">
44
+ <button type="submit" class="bg-primary hover:bg-indigo-700 text-white font-bold py-3 px-8 rounded-full shadow-md transition-all flex items-center gap-2">
45
+ <span>Generate</span> <span>✨</span>
46
+ </button>
47
+ <button type="button" id="clearCacheBtn" class="bg-zinc-400 hover:bg-zinc-500 text-white font-bold py-3 px-6 rounded-full shadow-md transition-all">Clear Cache πŸ”„</button>
48
+ </div>
49
+ </form>
50
+ <div id="resultCard" class="mt-8 hidden">
51
+ <div class="rounded-2xl bg-bgLight dark:bg-zinc-800 p-6 shadow-lg border border-zinc-200 dark:border-zinc-700">
52
+ <div class="flex items-center gap-2 mb-4">
53
+ <span class="text-2xl">πŸ“Š</span>
54
+ <h2 class="text-xl font-bold text-primary dark:text-accent">Scores</h2>
55
+ </div>
56
+ <div id="scores" class="mb-4 text-zinc-800 dark:text-zinc-100"></div>
57
+ <div class="flex items-center gap-2 mb-2">
58
+ <span class="text-2xl">πŸ’¬</span>
59
+ <h2 class="text-lg font-bold text-primary dark:text-accent">Comments</h2>
60
+ </div>
61
+ <div id="comments" class="mb-4 text-zinc-700 dark:text-zinc-200"></div>
62
+ <div class="flex items-center gap-2 mb-2">
63
+ <span class="text-2xl">✏️</span>
64
+ <h2 class="text-lg font-bold text-primary dark:text-accent">Suggested Prompt</h2>
65
+ </div>
66
+ <blockquote id="suggested" class="p-4 bg-zinc-100 dark:bg-zinc-900 rounded-xl text-zinc-800 dark:text-zinc-100"></blockquote>
67
+ </div>
68
+ <div id="cacheStatus" class="mt-4 text-xs text-zinc-500 dark:text-zinc-400 text-center"></div>
69
+ </div>
70
+ </div>
71
+ <footer class="mt-8 text-xs text-zinc-400 dark:text-zinc-600 text-center">
72
+ &copy; 2024 AI Prompt Auditor. Powered by Flan-T5.
73
+ </footer>
74
  </div>
 
75
  <script>
76
+ // Dark/Light mode toggle
77
+ const toggleTheme = document.getElementById('toggleTheme');
78
+ const html = document.documentElement;
79
+ const themeIcon = document.getElementById('themeIcon');
80
+ const sunIcon = document.getElementById('sunIcon');
81
+ const moonIcon = document.getElementById('moonIcon');
82
+ function setTheme(dark) {
83
+ if (dark) {
84
+ html.classList.add('dark');
85
+ sunIcon.classList.add('hidden');
86
+ moonIcon.classList.remove('hidden');
87
+ localStorage.setItem('theme', 'dark');
88
+ } else {
89
+ html.classList.remove('dark');
90
+ sunIcon.classList.remove('hidden');
91
+ moonIcon.classList.add('hidden');
92
+ localStorage.setItem('theme', 'light');
93
+ }
94
+ }
95
+ toggleTheme.onclick = () => setTheme(!html.classList.contains('dark'));
96
+ // On load
97
+ if (localStorage.getItem('theme') === 'dark' || (window.matchMedia('(prefers-color-scheme: dark)').matches && !localStorage.getItem('theme'))) {
98
+ setTheme(true);
99
+ } else {
100
+ setTheme(false);
101
+ }
102
 
103
+ // Form handling
104
+ const promptForm = document.getElementById('promptForm');
105
+ const resultCard = document.getElementById('resultCard');
106
+ const scoresDiv = document.getElementById('scores');
107
+ const commentsDiv = document.getElementById('comments');
108
+ const suggestedDiv = document.getElementById('suggested');
109
+ const cacheStatusDiv = document.getElementById('cacheStatus');
110
+ const clearCacheBtn = document.getElementById('clearCacheBtn');
111
+
112
+ promptForm.onsubmit = async (e) => {
113
+ e.preventDefault();
114
  const prompt = document.getElementById('prompt').value.trim();
115
  const context = document.getElementById('context').value.trim();
 
116
  if (!prompt) return alert("Please enter a prompt!");
117
+ resultCard.classList.add('hidden');
118
+ cacheStatusDiv.innerHTML = '';
119
+ scoresDiv.innerHTML = commentsDiv.innerHTML = suggestedDiv.innerHTML = '⏳ Generating...';
120
  try {
121
  const response = await fetch("/generate", {
122
  method: "POST",
 
125
  });
126
  const data = await response.json();
127
  const raw = data.response || "❌ No response";
 
128
  // Parse sections
129
  const scoresMatch = raw.match(/Scores:\s*(.*?)\s*Comments:/s);
130
  const commentsMatch = raw.match(/Comments:\s*(.*?)\s*Suggested:/s);
131
  const suggestedMatch = raw.match(/Suggested:\s*(.*)/s);
 
 
132
  if (scoresMatch) {
133
  const scores = scoresMatch[1].split(",").map(s => s.trim()).join("<br>");
134
+ scoresDiv.innerHTML = scores;
135
+ } else {
136
+ scoresDiv.innerHTML = '❌ Could not parse scores!';
137
  }
138
  if (commentsMatch) {
139
  const comments = commentsMatch[1].split(",").map(s => s.trim()).join("<br>");
140
+ commentsDiv.innerHTML = comments;
141
+ } else {
142
+ commentsDiv.innerHTML = '❌ Could not parse comments!';
143
  }
144
  if (suggestedMatch) {
145
+ suggestedDiv.innerHTML = suggestedMatch[1].trim();
146
+ } else {
147
+ suggestedDiv.innerHTML = '❌ Could not parse suggestion!';
148
  }
149
+ resultCard.classList.remove('hidden');
150
+ cacheStatusDiv.innerHTML = "βœ… Response cached for consistency";
151
+ } catch (err) {
152
+ scoresDiv.innerHTML = commentsDiv.innerHTML = suggestedDiv.innerHTML = "❌ Error: " + err;
153
+ resultCard.classList.remove('hidden');
154
+ cacheStatusDiv.innerHTML = '';
155
+ }
156
+ };
157
 
158
+ clearCacheBtn.onclick = async () => {
159
+ try {
160
+ const response = await fetch("/clear_cache", {
161
+ method: "POST",
162
+ headers: { "Content-Type": "application/json" }
163
+ });
164
+ const data = await response.json();
165
+ cacheStatusDiv.innerHTML = "πŸ”„ Cache cleared! Next generation will be fresh.";
166
+ resultCard.classList.add('hidden');
167
  } catch (err) {
168
+ cacheStatusDiv.innerHTML = "❌ Error clearing cache: " + err;
169
  }
170
  };
171
  </script>
172
  </body>
173
+ </html>