|
import os
|
|
from flask import Flask, render_template, request, send_file
|
|
from diffusers import DiffusionPipeline
|
|
from io import BytesIO
|
|
from PIL import Image
|
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
pipe = DiffusionPipeline.from_pretrained("sd-legacy/stable-diffusion-v1-5")
|
|
|
|
|
|
@app.route('/')
|
|
def index():
|
|
return render_template('index.html')
|
|
|
|
|
|
@app.route('/generate', methods=['POST'])
|
|
def generate_image():
|
|
try:
|
|
|
|
prompt = request.form['prompt']
|
|
|
|
|
|
image = pipe(prompt).images[0]
|
|
|
|
|
|
img_io = BytesIO()
|
|
image.save(img_io, 'PNG')
|
|
img_io.seek(0)
|
|
|
|
|
|
return send_file(img_io, mimetype='image/png')
|
|
except Exception as e:
|
|
|
|
return f"Bir hata oluştu: {str(e)}"
|
|
|
|
if __name__ == '__main__':
|
|
app.run(debug=True)
|
|
|