Image does not render on after ai image is generated and response has finished

I am coming back to development after years of not working on anything so my skills are rather rusty and I apologize for any improper syntax and formatting issues presented in advance.

I am currently working on a little web app project that takes a text prompt and generates an image using googles aivertex and gemini.

Here is some code snippets for review.

HTML Template

<body>
    <h1>Turn your words into art!</h1>
    <p>Enter a description of the image you want to generate.</p>
    <form target="_blank" id="text-form" action="/my_prompt" onsubmit="dontredict('myindex.html')" method="post">
        <label for="text-input">Text Prompt:</label>
        <textarea id="text-input" name="text" rows="5" placeholder="e.g. A cat riding a bicycle on Mars"></textarea>
        <button type="submit">Generate Image</button>
    </form>
    <div id="image-container">
        {% if img_data %}
        <h1>Your generated image will appear here.</h1>
        <img id="picture" style="height: 300px;" src="{{url_for('static',filename='my-output.png')}}">
        {% else %}
        <h1>Image will be render here...</h1>
        {% endif %}
    </div>
        <!--Jquery Cdn -->
        <script src="https://code.jquery.com/jquery-3.5.1.js" integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
            crossorigin="anonymous"></script>
        
        <script type="text/javascript">
           function dontredict(dynamicUrl){ 
            $(document).on('submit', '#text-form', function (e) {
                e.preventDefault();
                console.log('button smashed');
                $.ajax({
                    type: 'POST',
                    url: '/my_prompt',
                    data: {
                        text: $("#text-input").val()
                    },
                    success: function () {
                        alert('saved');
                    }
                })
            });
        }
        </script>
</body>

Python text-to-image.py

def disp_image():
    if os.path.exists(output_file):
        im = Image.open("static/my-output.png")
        data = io.BytesIO()
        im.save(data, "PNG")
        encoded_img_data = base64.b64encode(data.getvalue())
        img_data=encoded_img_data.decode('utf-8')
        return render_template("myindex.html", img_data=img_data)
    #if os.path.exists(output_file):
            #return redirect(url_for('static/my-output.png'))

@app.route('/my_prompt', methods = ['POST'])
@cross_origin()
def imggen():
   print("inside gen")
   if request.method == 'POST':
      prompt = request.form.get("text")
      logger.info('%s This is the prompt: ', prompt)
      print(prompt); 
      print("after prompt") 
      model = ImageGenerationModel.from_pretrained("imagegeneration@006")
      images = model.generate_images(
        prompt=prompt,
        # Optional parameters
        number_of_images=1,
        language="en",
        # You can't use a seed value and watermark at the same time.
        # add_watermark=False,
        # seed=100,
        aspect_ratio="1:1",
        safety_filter_level="block_some",
        person_generation="allow_adult",
        )
      images[0].save(location=output_file, include_generation_parameters=False)
      print(f"Created output image using {len(images[0]._image_bytes)} bytes")
      print(disp_image())
      return disp_image()
       
   else:
        print("error")

The issues I’m having is when the text is posted and comes back with the generated image it get saved properly to the static image folder (using flask and python) but, it does not display or render to the html page. I am also aware that some of the code may be redundant. Let me know what I am doing wrong, in terms of displaying the image to the actual html page, Thank you.

New contributor

Christopher Opitz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật