Update myapp.py
Browse files
myapp.py
CHANGED
|
@@ -12,7 +12,41 @@ pipe = DiffusionPipeline.from_pretrained("prompthero/openjourney-v4").to("cpu")
|
|
| 12 |
|
| 13 |
@myapp.route('/')
|
| 14 |
def index():
|
| 15 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
@myapp.route('/generate_image', methods=['POST'])
|
| 18 |
def generate_image():
|
|
|
|
| 12 |
|
| 13 |
@myapp.route('/')
|
| 14 |
def index():
|
| 15 |
+
return '''
|
| 16 |
+
<html>
|
| 17 |
+
<body>
|
| 18 |
+
<h1>Welcome to the Image Generation API!</h1>
|
| 19 |
+
<form id="input-form">
|
| 20 |
+
<label for="prompt">Enter your prompt:</label><br>
|
| 21 |
+
<input type="text" id="prompt" name="prompt"><br><br>
|
| 22 |
+
<button type="submit">Generate Image</button>
|
| 23 |
+
</form>
|
| 24 |
+
<div id="spinner" style="display:none;">Generating image, please wait...</div>
|
| 25 |
+
<div id="result"></div>
|
| 26 |
+
<script>
|
| 27 |
+
document.getElementById('input-form').onsubmit = async (e) => {
|
| 28 |
+
e.preventDefault();
|
| 29 |
+
document.getElementById('spinner').style.display = 'block';
|
| 30 |
+
const prompt = document.getElementById('prompt').value;
|
| 31 |
+
|
| 32 |
+
const response = await fetch('/generate_image', {
|
| 33 |
+
method: 'POST',
|
| 34 |
+
headers: { 'Content-Type': 'application/json' },
|
| 35 |
+
body: JSON.stringify({ prompt })
|
| 36 |
+
});
|
| 37 |
+
|
| 38 |
+
const data = await response.json();
|
| 39 |
+
document.getElementById('spinner').style.display = 'none';
|
| 40 |
+
if (response.ok) {
|
| 41 |
+
document.getElementById('result').innerHTML = `<h2>Image Generated:</h2><img src="${data.image_path}" alt="Generated Image">`;
|
| 42 |
+
} else {
|
| 43 |
+
document.getElementById('result').innerText = 'Error generating image: ' + data.error;
|
| 44 |
+
}
|
| 45 |
+
};
|
| 46 |
+
</script>
|
| 47 |
+
</body>
|
| 48 |
+
</html>
|
| 49 |
+
'''
|
| 50 |
|
| 51 |
@myapp.route('/generate_image', methods=['POST'])
|
| 52 |
def generate_image():
|