Karan236 commited on
Commit
3ed63e3
·
verified ·
1 Parent(s): e72ed51

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -5
app.py CHANGED
@@ -1,10 +1,22 @@
1
  from flask import Flask, render_template, request
2
- from transformers import Text2ImagePipeline
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  app = Flask(__name__)
5
 
6
- # Load the Hugging Face model for text-to-image generation
7
- text_to_image = Text2ImagePipeline(model="text2img")
8
 
9
  @app.route('/')
10
  def home():
@@ -17,11 +29,24 @@ def generate():
17
  text = request.form['text']
18
 
19
  # Generate image from text
20
- image = text_to_image(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  # Save the generated image (for simplicity, you can send it directly to the user)
23
  # You can save it to a temporary file or memory depending on your needs
24
- image.save("static/generated_image.png")
25
 
26
  return render_template('index.html', generated=True)
27
 
 
1
  from flask import Flask, render_template, request
2
+
3
+
4
+ import torch
5
+ from diffusers import DiffusionPipeline
6
+
7
+ pipe = DiffusionPipeline.from_pretrained(
8
+ "cagliostrolab/animagine-xl-3.1",
9
+ torch_dtype=torch.float16,
10
+ use_safetensors=True,
11
+ )
12
+ pipe.to('cpu')
13
+
14
+
15
+
16
 
17
  app = Flask(__name__)
18
 
19
+
 
20
 
21
  @app.route('/')
22
  def home():
 
29
  text = request.form['text']
30
 
31
  # Generate image from text
32
+ #image = text_to_image(text)
33
+ prompt = text
34
+ negative_prompt = "nsfw, lowres, (bad), text, error, fewer, extra, missing, worst quality, jpeg artifacts, low quality, watermark, unfinished, displeasing, oldest, early, chromatic aberration, signature, extra digits, artistic error, username, scan, [abstract]"
35
+
36
+ image = pipe(
37
+ prompt,
38
+ negative_prompt=negative_prompt,
39
+ width=832,
40
+ height=1216,
41
+ guidance_scale=7,
42
+ num_inference_steps=28
43
+ ).images[0]
44
+
45
+ image.save("./output/asuka_test.png")
46
 
47
  # Save the generated image (for simplicity, you can send it directly to the user)
48
  # You can save it to a temporary file or memory depending on your needs
49
+ #image.save("static/generated_image.png")
50
 
51
  return render_template('index.html', generated=True)
52