broadfield-dev commited on
Commit
73623b8
·
verified ·
1 Parent(s): 286b23a

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +161 -19
index.html CHANGED
@@ -1,19 +1,161 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>API Client for Secure Decoder Plugin</title>
7
+ <style>
8
+ :root {
9
+ --primary-color: #3b82f6;
10
+ --primary-hover: #2563eb;
11
+ --border-color: #d1d5db;
12
+ --background-color: #f9fafb;
13
+ --text-color: #1f2937;
14
+ --error-color: #ef4444;
15
+ --success-color: #22c55e;
16
+ }
17
+ body {
18
+ font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
19
+ line-height: 1.6;
20
+ max-width: 700px;
21
+ margin: 2rem auto;
22
+ padding: 0 1rem;
23
+ color: var(--text-color);
24
+ }
25
+ main {
26
+ display: flex;
27
+ flex-direction: column;
28
+ gap: 1.5rem;
29
+ border: 1px solid var(--border-color);
30
+ padding: 1.5rem;
31
+ border-radius: 0.5rem;
32
+ background-color: white;
33
+ }
34
+ h1 {
35
+ color: #111827;
36
+ text-align: center;
37
+ }
38
+ section {
39
+ display: flex;
40
+ flex-direction: column;
41
+ gap: 0.5rem;
42
+ }
43
+ label {
44
+ font-weight: 600;
45
+ }
46
+ input[type="text"], input[type="file"] {
47
+ font-size: 1rem;
48
+ padding: 0.5rem 0.75rem;
49
+ border: 1px solid var(--border-color);
50
+ border-radius: 0.375rem;
51
+ }
52
+ button {
53
+ font-size: 1rem;
54
+ font-weight: 600;
55
+ padding: 0.75rem 1rem;
56
+ cursor: pointer;
57
+ border: none;
58
+ border-radius: 0.375rem;
59
+ background-color: var(--primary-color);
60
+ color: white;
61
+ transition: background-color 0.2s;
62
+ }
63
+ button:hover:not(:disabled) {
64
+ background-color: var(--primary-hover);
65
+ }
66
+ button:disabled {
67
+ background-color: #9ca3af;
68
+ cursor: not-allowed;
69
+ }
70
+ #result-output {
71
+ background: var(--background-color);
72
+ padding: 1rem;
73
+ border-radius: 5px;
74
+ white-space: pre-wrap;
75
+ word-wrap: break-word;
76
+ font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
77
+ min-height: 60px;
78
+ border: 1px solid var(--border-color);
79
+ }
80
+ .result-error { color: var(--error-color); }
81
+ .result-success { color: var(--success-color); }
82
+ </style>
83
+ </head>
84
+ <body>
85
+ <h1>Secure Decoder Plugin Client</h1>
86
+ <p style="text-align: center;">Use this page to test your deployed Hugging Face API. It sends an encrypted image to your secure server endpoint for decoding.</p>
87
+
88
+ <main>
89
+ <section>
90
+ <label for="api-url">1. Your Deployed API Endpoint URL:</label>
91
+ <input type="text" id="api-url" placeholder="https://broadfield-dev-keylock-rsa-js.static.hf.space/api/decode">
92
+ </section>
93
+
94
+ <section>
95
+ <label for="image-upload">2. Upload Image (Encrypted with Plugin's Public Key):</label>
96
+ <input type="file" id="image-upload" accept="image/png">
97
+ </section>
98
+
99
+ <button id="submit-button">Send to Plugin for Decoding</button>
100
+
101
+ <section>
102
+ <h3>Result from Server:</h3>
103
+ <div id="result-output">Awaiting input...</div>
104
+ </section>
105
+ </main>
106
+
107
+ <script>
108
+ const apiUrlInput = document.getElementById('api-url');
109
+ const imageInput = document.getElementById('image-upload');
110
+ const submitButton = document.getElementById('submit-button');
111
+ const resultOutput = document.getElementById('result-output');
112
+ submitButton.addEventListener('click', async () => {
113
+ const file = imageInput.files[0];
114
+ const apiUrl = apiUrlInput.value.trim();
115
+ // --- Input Validation ---
116
+ if (!apiUrl) {
117
+ resultOutput.textContent = 'Error: Please provide the API endpoint URL.';
118
+ resultOutput.className = 'result-error';
119
+ return;
120
+ }
121
+ if (!file) {
122
+ resultOutput.textContent = 'Error: Please select an image file to upload.';
123
+ resultOutput.className = 'result-error';
124
+ return;
125
+ }
126
+ // --- UI Feedback for Loading State ---
127
+ resultOutput.textContent = 'Uploading and decoding...';
128
+ resultOutput.className = '';
129
+ submitButton.disabled = true;
130
+ submitButton.textContent = 'Processing...';
131
+ // --- Prepare and Send the Request ---
132
+ const formData = new FormData();
133
+ formData.append('authImage', file); // 'authImage' must match the server's expected field name
134
+ try {
135
+ const response = await fetch(apiUrl, {
136
+ method: 'POST',
137
+ body: formData,
138
+ });
139
+ const result = await response.json();
140
+ if (!response.ok) {
141
+ // If the server returns an error (like 400 or 500), throw it
142
+ throw new Error(result.error || `Server responded with status ${response.status}`);
143
+ }
144
+
145
+ // --- Handle Success ---
146
+ resultOutput.className = 'result-success';
147
+ resultOutput.textContent = `✅ Success! Decoded Data:\n\n${JSON.stringify(result.data, null, 2)}`;
148
+ } catch (error) {
149
+ // --- Handle Failure (Network error or server error) ---
150
+ resultOutput.className = 'result-error';
151
+ resultOutput.textContent = `❌ API Request Failed:\n\n${error.message}`;
152
+ console.error('API Error:', error);
153
+ } finally {
154
+ // --- Reset UI ---
155
+ submitButton.disabled = false;
156
+ submitButton.textContent = 'Send to Plugin for Decoding';
157
+ }
158
+ });
159
+ </script>
160
+ </body>
161
+ </html>