Update app.py
Browse files
app.py
CHANGED
@@ -113,108 +113,147 @@ def restore_image():
|
|
113 |
@app.route('/')
|
114 |
def index():
|
115 |
return """
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
|
|
157 |
<div class="form-group">
|
158 |
<label for="weight">Weight (only for CodeFormer):</label>
|
159 |
<input type="range" id="weight" name="weight" min="0" max="100" value="50">
|
160 |
<span id="weightValue">50</span>
|
161 |
</div>
|
162 |
-->
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
218 |
"""
|
219 |
|
220 |
if __name__ == '__main__':
|
|
|
113 |
@app.route('/')
|
114 |
def index():
|
115 |
return """
|
116 |
+
<!DOCTYPE html>
|
117 |
+
<html>
|
118 |
+
|
119 |
+
<head>
|
120 |
+
<title>Image Upscaling & Restoration API</title>
|
121 |
+
<style>
|
122 |
+
body { font-family: Arial, sans-serif; max-width: 800px; margin: 0 auto; padding: 20px; }
|
123 |
+
.container { border: 1px solid #ddd; padding: 20px; border-radius: 5px; }
|
124 |
+
.form-group { margin-bottom: 15px; }
|
125 |
+
label { display: block; margin-bottom: 5px; }
|
126 |
+
input, select { width: 100%; padding: 8px; box-sizing: border-box; }
|
127 |
+
button { background-color: #4CAF50; color: white; padding: 10px 15px; border: none; border-radius: 4px; cursor: pointer; }
|
128 |
+
button:hover { background-color: #45a049; }
|
129 |
+
#result { margin-top: 20px; }
|
130 |
+
#preview { max-width: 100%; margin-top: 10px; }
|
131 |
+
</style>
|
132 |
+
</head>
|
133 |
+
|
134 |
+
<body>
|
135 |
+
<h1>Image Upscaling & Restoration API</h1>
|
136 |
+
<div class="container">
|
137 |
+
<form id="uploadForm" enctype="multipart/form-data">
|
138 |
+
<div class="form-group">
|
139 |
+
<label for="file">Upload Image:</label>
|
140 |
+
<input type="file" id="file" name="file" required>
|
141 |
+
</div>
|
142 |
+
<div class="form-group">
|
143 |
+
<label for="version">Version:</label>
|
144 |
+
<select id="version" name="version">
|
145 |
+
<option value="v1.2">v1.2</option>
|
146 |
+
<option value="v1.3">v1.3</option>
|
147 |
+
<option value="v1.4" selected>v1.4</option>
|
148 |
+
<option value="RestoreFormer">RestoreFormer</option>
|
149 |
+
<option value="CodeFormer">CodeFormer</option>
|
150 |
+
<option value="RealESR-General-x4v3">RealESR-General-x4v3</option>
|
151 |
+
</select>
|
152 |
+
</div>
|
153 |
+
<div class="form-group">
|
154 |
+
<label for="scale">Rescaling factor:</label>
|
155 |
+
<input type="number" id="scale" name="scale" value="2" step="0.1" min="1" max="4" required>
|
156 |
+
</div>
|
157 |
+
<!--
|
158 |
<div class="form-group">
|
159 |
<label for="weight">Weight (only for CodeFormer):</label>
|
160 |
<input type="range" id="weight" name="weight" min="0" max="100" value="50">
|
161 |
<span id="weightValue">50</span>
|
162 |
</div>
|
163 |
-->
|
164 |
+
<button type="submit">Process Image</button>
|
165 |
+
</form>
|
166 |
+
<div id="result">
|
167 |
+
<h3>Result:</h3>
|
168 |
+
<div id="outputContainer" style="display: none;">
|
169 |
+
<img id="preview" src="" alt="Processed Image">
|
170 |
+
<a id="downloadLink" href="#" download>Download Image</a>
|
171 |
+
</div>
|
172 |
+
</div>
|
173 |
+
</div>
|
174 |
+
<script>
|
175 |
+
document.getElementById('uploadForm').addEventListener('submit', function(e) {
|
176 |
+
e.preventDefault();
|
177 |
+
|
178 |
+
const formData = new FormData();
|
179 |
+
formData.append('file', document.getElementById('file').files[0]);
|
180 |
+
formData.append('version', document.getElementById('version').value);
|
181 |
+
formData.append('scale', document.getElementById('scale').value);
|
182 |
+
// formData.append('weight', document.getElementById('weight').value); // CodeFormer用
|
183 |
+
|
184 |
+
fetch('/api/restore', {
|
185 |
+
method: 'POST',
|
186 |
+
body: formData
|
187 |
+
})
|
188 |
+
.then(response => {
|
189 |
+
if (!response.ok) {
|
190 |
+
return response.json().then(err => { throw new Error(err.error || 'Unknown error'); });
|
191 |
+
}
|
192 |
+
return response.blob();
|
193 |
+
})
|
194 |
+
.then(blob => {
|
195 |
+
const url = URL.createObjectURL(blob);
|
196 |
+
const preview = document.getElementById('preview');
|
197 |
+
const downloadLink = document.getElementById('downloadLink');
|
198 |
+
const outputContainer = document.getElementById('outputContainer');
|
199 |
+
|
200 |
+
preview.src = url;
|
201 |
+
downloadLink.href = url;
|
202 |
+
downloadLink.download = 'restored_' + document.getElementById('file').files[0].name;
|
203 |
+
outputContainer.style.display = 'block';
|
204 |
+
})
|
205 |
+
.catch(error => {
|
206 |
+
alert('Error: ' + error.message);
|
207 |
+
});
|
208 |
+
});
|
209 |
+
|
210 |
+
</script>
|
211 |
+
<div id="apiUsage" style="margin-top: 30px;">
|
212 |
+
<h3>API:</h3> <pre><code id="apiCode" style="white-space: pre-wrap; background: #f8f8f8; padding: 10px; border-radius: 5px;"></code></pre>
|
213 |
+
</div>
|
214 |
+
<script>
|
215 |
+
function updateApiUsage() {
|
216 |
+
const fileInput = document.getElementById('file');
|
217 |
+
const version = document.getElementById('version').value;
|
218 |
+
const scale = document.getElementById('scale').value;
|
219 |
+
const baseURL = window.location.origin;
|
220 |
+
|
221 |
+
let codeSnippet = `
|
222 |
+
const formData = new FormData();
|
223 |
+
formData.append('file', "file");
|
224 |
+
formData.append('version', '${version}');
|
225 |
+
formData.append('scale', '${scale}');
|
226 |
+
|
227 |
+
fetch('${baseURL}/api/restore', {
|
228 |
+
method: 'POST',
|
229 |
+
body: formData
|
230 |
+
})
|
231 |
+
.then(response => {
|
232 |
+
if (!response.ok) {
|
233 |
+
return response.json().then(err => { throw new Error(err.error || 'Unknown error'); });
|
234 |
+
}
|
235 |
+
return response.blob();
|
236 |
+
})
|
237 |
+
.then(blob => {
|
238 |
+
const url = URL.createObjectURL(blob);
|
239 |
+
|
240 |
+
})
|
241 |
+
.catch(error => {
|
242 |
+
console.error('Error:', error.message);
|
243 |
+
});`.trim();
|
244 |
+
|
245 |
+
document.getElementById('apiCode').textContent = codeSnippet;
|
246 |
+
}
|
247 |
+
|
248 |
+
document.getElementById('uploadForm').addEventListener('change', updateApiUsage);
|
249 |
+
document.getElementById('version').addEventListener('change', updateApiUsage);
|
250 |
+
document.getElementById('scale').addEventListener('input', updateApiUsage);
|
251 |
+
|
252 |
+
updateApiUsage();
|
253 |
+
</script>
|
254 |
+
</body>
|
255 |
+
|
256 |
+
</html>
|
257 |
"""
|
258 |
|
259 |
if __name__ == '__main__':
|