from flask import Flask, render_template, request from transformers import Text2ImagePipeline app = Flask(__name__) # Load the Hugging Face model for text-to-image generation text_to_image = Text2ImagePipeline(model="text2img") @app.route('/') def home(): return render_template('index.html') @app.route('/generate', methods=['POST']) def generate(): if request.method == 'POST': # Get text input from the form text = request.form['text'] # Generate image from text image = text_to_image(text) # Save the generated image (for simplicity, you can send it directly to the user) # You can save it to a temporary file or memory depending on your needs image.save("static/generated_image.png") return render_template('index.html', generated=True) if __name__ == '__main__': app.run(debug=True)