File size: 873 Bytes
cecee6f
 
bab5f3b
cecee6f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)