Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -101,13 +101,17 @@ index_html = """
|
|
| 101 |
|
| 102 |
<button type="submit">Generate Image</button>
|
| 103 |
</form>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
</body>
|
| 105 |
</html>
|
| 106 |
"""
|
| 107 |
|
| 108 |
@app.route('/')
|
| 109 |
def index():
|
| 110 |
-
return render_template_string(index_html)
|
| 111 |
|
| 112 |
@app.route('/generate', methods=['GET'])
|
| 113 |
def generate_image():
|
|
@@ -133,8 +137,17 @@ def generate_image():
|
|
| 133 |
image.save(img_io, 'PNG')
|
| 134 |
img_io.seek(0)
|
| 135 |
|
| 136 |
-
#
|
| 137 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
if __name__ == '__main__':
|
|
|
|
|
|
|
| 140 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 101 |
|
| 102 |
<button type="submit">Generate Image</button>
|
| 103 |
</form>
|
| 104 |
+
{% if image_url %}
|
| 105 |
+
<h2>Generated Image:</h2>
|
| 106 |
+
<img src="{{ image_url }}" alt="Generated Image" style="max-width: 100%; height: auto;">
|
| 107 |
+
{% endif %}
|
| 108 |
</body>
|
| 109 |
</html>
|
| 110 |
"""
|
| 111 |
|
| 112 |
@app.route('/')
|
| 113 |
def index():
|
| 114 |
+
return render_template_string(index_html, image_url=None)
|
| 115 |
|
| 116 |
@app.route('/generate', methods=['GET'])
|
| 117 |
def generate_image():
|
|
|
|
| 137 |
image.save(img_io, 'PNG')
|
| 138 |
img_io.seek(0)
|
| 139 |
|
| 140 |
+
# Create a unique filename for the image
|
| 141 |
+
image_filename = f"generated_image_{random.randint(1, 10000)}.png"
|
| 142 |
+
|
| 143 |
+
# Save the image to a file
|
| 144 |
+
image.save(image_filename)
|
| 145 |
+
|
| 146 |
+
# Return the index page with the generated image URL
|
| 147 |
+
image_url = f"/static/{image_filename}"
|
| 148 |
+
return render_template_string(index_html, image_url=image_url)
|
| 149 |
|
| 150 |
if __name__ == '__main__':
|
| 151 |
+
# Ensure the 'static' folder exists for saving images
|
| 152 |
+
os.makedirs('static', exist_ok=True)
|
| 153 |
app.run(host='0.0.0.0', port=7860)
|