usmansafdarktk commited on
Commit
4cb09ae
·
1 Parent(s): 5b2b9b0

imporved index.html

Browse files
Files changed (1) hide show
  1. static/index.html +146 -151
static/index.html CHANGED
@@ -3,165 +3,160 @@
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
- <title>LaMini-LM API</title>
7
- <script src="https://cdn.jsdelivr.net/npm/react@18.2.0/umd/react.production.min.js"></script>
8
- <script src="https://cdn.jsdelivr.net/npm/react-dom@18.2.0/umd/react-dom.production.min.js"></script>
9
- <script src="https://cdn.jsdelivr.net/npm/babel-standalone@7.22.9/babel.min.js"></script>
10
  <script src="https://cdn.tailwindcss.com"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  </head>
12
- <body class="bg-gray-100 min-h-screen flex items-center justify-center">
13
- <div id="root"></div>
14
- <script type="text/babel">
15
- function App() {
16
- const [instruction, setInstruction] = React.useState('');
17
- const [maxLength, setMaxLength] = React.useState(100);
18
- const [temperature, setTemperature] = React.useState(1.0);
19
- const [topP, setTopP] = React.useState(0.9);
20
- const [generatedText, setGeneratedText] = React.useState('');
21
- const [error, setError] = React.useState('');
22
- const [isLoading, setIsLoading] = React.useState(false);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
 
24
- const handleSubmit = async (e) => {
25
- e.preventDefault();
26
- setError('');
27
- setGeneratedText('');
28
- setIsLoading(true);
 
29
 
30
- if (!instruction.trim()) {
31
- setError('Instruction cannot be empty.');
32
- setIsLoading(false);
33
- return;
34
- }
35
- if (maxLength < 10 || maxLength > 500) {
36
- setError('Max length must be between 10 and 500.');
37
- setIsLoading(false);
38
- return;
39
- }
40
- if (temperature <= 0 || temperature > 2) {
41
- setError('Temperature must be between 0 and 2.');
42
- setIsLoading(false);
43
- return;
44
- }
45
- if (topP <= 0 || topP > 1) {
46
- setError('Top P must be between 0 and 1.');
47
- setIsLoading(false);
48
- return;
49
- }
50
 
51
- try {
52
- const response = await fetch('/generate', {
53
- method: 'POST',
54
- headers: { 'Content-Type': 'application/json' },
55
- body: JSON.stringify({
56
- instruction,
57
- max_length: maxLength,
58
- temperature,
59
- top_p: topP,
60
- }),
61
- });
62
- const data = await response.json();
63
- if (response.ok) {
64
- setGeneratedText(data.generated_text);
65
- } else {
66
- setError(data.detail?.[0]?.msg || 'Failed to generate text.');
67
- }
68
- } catch (err) {
69
- setError('Error connecting to the API. Please try again.');
70
- } finally {
71
- setIsLoading(false);
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  }
73
- };
 
 
 
 
 
 
74
 
75
- return (
76
- <div className="max-w-2xl mx-auto p-6 bg-white rounded-lg shadow-lg">
77
- <h1 className="text-3xl font-bold text-center text-gray-800 mb-6">
78
- LaMini-LM Text Generator
79
- </h1>
80
- <form onSubmit={handleSubmit} className="space-y-4">
81
- <div>
82
- <label htmlFor="instruction" className="block text-sm font-medium text-gray-700">
83
- Instruction
84
- </label>
85
- <textarea
86
- id="instruction"
87
- value={instruction}
88
- onChange={(e) => setInstruction(e.target.value)}
89
- className="mt-1 w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
90
- rows="4"
91
- placeholder="e.g., Tell me about camels"
92
- ></textarea>
93
- </div>
94
- <div>
95
- <label htmlFor="maxLength" className="block text-sm font-medium text-gray-700">
96
- Max Length (10–500)
97
- </label>
98
- <input
99
- id="maxLength"
100
- type="number"
101
- value={maxLength}
102
- onChange={(e) => setMaxLength(Number(e.target.value))}
103
- min="10"
104
- max="500"
105
- className="mt-1 w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
106
- />
107
- </div>
108
- <div>
109
- <label htmlFor="temperature" className="block text-sm font-medium text-gray-700">
110
- Temperature (0–2)
111
- </label>
112
- <input
113
- id="temperature"
114
- type="number"
115
- step="0.1"
116
- value={temperature}
117
- onChange={(e) => setTemperature(Number(e.target.value))}
118
- min="0"
119
- max="2"
120
- className="mt-1 w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
121
- />
122
- </div>
123
- <div>
124
- <label htmlFor="topP" className="block text-sm font-medium text-gray-700">
125
- Top P (0–1)
126
- </label>
127
- <input
128
- id="topP"
129
- type="number"
130
- step="0.1"
131
- value={topP}
132
- onChange={(e) => setTopP(Number(e.target.value))}
133
- min="0"
134
- max="1"
135
- className="mt-1 w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
136
- />
137
- </div>
138
- <button
139
- type="submit"
140
- disabled={isLoading}
141
- className={`w-full py-2 px-4 bg-blue-600 text-white rounded-md hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 ${
142
- isLoading ? 'opacity-50 cursor-not-allowed' : ''
143
- }`}
144
- >
145
- {isLoading ? 'Generating...' : 'Generate Text'}
146
- </button>
147
- </form>
148
- {error && (
149
- <div className="mt-4 p-4 bg-red-100 text-red-700 rounded-md">
150
- {error}
151
- </div>
152
- )}
153
- {generatedText && (
154
- <div className="mt-4 p-4 bg-gray-100 rounded-md">
155
- <h2 className="text-lg font-semibold text-gray-800">Generated Text:</h2>
156
- <p className="mt-2 text-gray-600">{generatedText}</p>
157
- </div>
158
- )}
159
- </div>
160
- );
161
  }
162
-
163
- const root = ReactDOM.createRoot(document.getElementById('root'));
164
- root.render(<App />);
165
  </script>
166
  </body>
167
  </html>
 
3
  <head>
4
  <meta charset="UTF-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>LaMini-LM Text Generator</title>
 
 
 
7
  <script src="https://cdn.tailwindcss.com"></script>
8
+ <style>
9
+ .spinner {
10
+ display: none;
11
+ border: 4px solid rgba(0, 0, 0, 0.1);
12
+ border-left-color: #3b82f6;
13
+ border-radius: 50%;
14
+ width: 24px;
15
+ height: 24px;
16
+ animation: spin 1s linear infinite;
17
+ }
18
+ @keyframes spin {
19
+ to { transform: rotate(360deg); }
20
+ }
21
+ </style>
22
  </head>
23
+ <body class="bg-gray-100 min-h-screen flex items-center justify-center px-4">
24
+ <div class="max-w-lg w-full bg-white rounded-xl shadow-lg p-6">
25
+ <h1 class="text-2xl font-bold text-center text-gray-800 mb-6">LaMini-LM Text Generator</h1>
26
+ <form id="generate-form" class="space-y-4">
27
+ <div>
28
+ <label for="instruction" class="block text-sm font-medium text-gray-700">Instruction</label>
29
+ <textarea
30
+ id="instruction"
31
+ class="mt-1 w-full p-3 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
32
+ rows="4"
33
+ placeholder="e.g., Tell me about camels"
34
+ required
35
+ ></textarea>
36
+ </div>
37
+ <div class="grid grid-cols-1 sm:grid-cols-3 gap-4">
38
+ <div>
39
+ <label for="max-length" class="block text-sm font-medium text-gray-700">Max Length (10–500)</label>
40
+ <input
41
+ id="max-length"
42
+ type="number"
43
+ min="10"
44
+ max="500"
45
+ value="100"
46
+ class="mt-1 w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
47
+ required
48
+ />
49
+ </div>
50
+ <div>
51
+ <label for="temperature" class="block text-sm font-medium text-gray-700">Temperature (0–2)</label>
52
+ <input
53
+ id="temperature"
54
+ type="number"
55
+ step="0.1"
56
+ min="0"
57
+ max="2"
58
+ value="1.0"
59
+ class="mt-1 w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
60
+ required
61
+ />
62
+ </div>
63
+ <div>
64
+ <label for="top-p" class="block text-sm font-medium text-gray-700">Top P (0–1)</label>
65
+ <input
66
+ id="top-p"
67
+ type="number"
68
+ step="0.1"
69
+ min="0"
70
+ max="1"
71
+ value="0.9"
72
+ class="mt-1 w-full p-2 border border-gray-300 rounded-md focus:ring-blue-500 focus:border-blue-500"
73
+ required
74
+ />
75
+ </div>
76
+ </div>
77
+ <button
78
+ type="submit"
79
+ class="w-full py-2 px-4 bg-gradient-to-r from-blue-500 to-indigo-600 text-white font-semibold rounded-md hover:from-blue-600 hover:to-indigo-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 flex items-center justify-center"
80
+ >
81
+ <span id="button-text">Generate Text</span>
82
+ <span id="spinner" class="spinner ml-2"></span>
83
+ </button>
84
+ </form>
85
+ <div id="error" class="mt-4 hidden p-3 bg-red-100 text-red-700 rounded-md"></div>
86
+ <div id="result" class="mt-4 hidden p-4 bg-gray-50 rounded-md">
87
+ <h2 class="text-lg font-semibold text-gray-800">Generated Text:</h2>
88
+ <p id="generated-text" class="mt-2 text-gray-600"></p>
89
+ </div>
90
+ </div>
91
+ <script>
92
+ const form = document.getElementById('generate-form');
93
+ const errorDiv = document.getElementById('error');
94
+ const resultDiv = document.getElementById('result');
95
+ const generatedText = document.getElementById('generated-text');
96
+ const buttonText = document.getElementById('button-text');
97
+ const spinner = document.getElementById('spinner');
98
 
99
+ form.addEventListener('submit', async (e) => {
100
+ e.preventDefault();
101
+ errorDiv.classList.add('hidden');
102
+ resultDiv.classList.add('hidden');
103
+ buttonText.textContent = 'Generating...';
104
+ spinner.style.display = 'block';
105
 
106
+ const instruction = document.getElementById('instruction').value;
107
+ const maxLength = Number(document.getElementById('max-length').value);
108
+ const temperature = Number(document.getElementById('temperature').value);
109
+ const topP = Number(document.getElementById('top-p').value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
+ if (!instruction.trim()) {
112
+ showError('Instruction cannot be empty.');
113
+ return;
114
+ }
115
+ if (maxLength < 10 || maxLength > 500) {
116
+ showError('Max length must be between 10 and 500.');
117
+ return;
118
+ }
119
+ if (temperature <= 0 || temperature > 2) {
120
+ showError('Temperature must be between 0 and 2.');
121
+ return;
122
+ }
123
+ if (topP <= 0 || topP > 1) {
124
+ showError('Top P must be between 0 and 1.');
125
+ return;
126
+ }
127
+
128
+ try {
129
+ const response = await fetch('/generate', {
130
+ method: 'POST',
131
+ headers: { 'Content-Type': 'application/json' },
132
+ body: JSON.stringify({
133
+ instruction,
134
+ max_length: maxLength,
135
+ temperature,
136
+ top_p: topP,
137
+ }),
138
+ });
139
+ const data = await response.json();
140
+ if (response.ok) {
141
+ resultDiv.classList.remove('hidden');
142
+ generatedText.textContent = data.generated_text;
143
+ } else {
144
+ showError(data.detail?.[0]?.msg || 'Failed to generate text.');
145
  }
146
+ } catch (err) {
147
+ showError('Error connecting to the API. Please try again.');
148
+ } finally {
149
+ buttonText.textContent = 'Generate Text';
150
+ spinner.style.display = 'none';
151
+ }
152
+ });
153
 
154
+ function showError(message) {
155
+ errorDiv.textContent = message;
156
+ errorDiv.classList.remove('hidden');
157
+ buttonText.textContent = 'Generate Text';
158
+ spinner.style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
159
  }
 
 
 
160
  </script>
161
  </body>
162
  </html>