Jeevaaaa commited on
Commit
1bc7dae
·
verified ·
1 Parent(s): f45efff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -25
app.py CHANGED
@@ -1,9 +1,10 @@
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
 
 
3
  import os
4
- import subprocess
5
- import sys
6
 
 
7
  model_path = hf_hub_download(
8
  repo_id="calcuis/pony",
9
  filename="blackmagic-q4_k_m.gguf",
@@ -11,36 +12,34 @@ model_path = hf_hub_download(
11
  )
12
  print(f"Model ready at: {model_path}")
13
 
14
- def generate(prompt, negative_prompt="bad quality, blurry", steps=20):
15
- try:
16
- from diffusers import StableDiffusionPipeline
17
- import torch
18
-
19
- pipe = StableDiffusionPipeline.from_single_file(
20
- model_path,
21
- torch_dtype=torch.float32,
22
- )
23
- pipe.to("cpu")
24
-
25
- image = pipe(
26
- prompt=prompt,
27
- negative_prompt=negative_prompt,
28
- num_inference_steps=steps,
29
- ).images[0]
30
-
31
- return image
32
-
33
- except Exception as e:
34
- return f"Error: {str(e)}"
35
 
36
  demo = gr.Interface(
37
  fn=generate,
38
  inputs=[
39
  gr.Textbox(label="Prompt", value="a cute cat sitting on a bench"),
40
  gr.Textbox(label="Negative Prompt", value="bad quality, blurry"),
41
- gr.Slider(minimum=5, maximum=30, value=15, step=1, label="Steps (lower = faster)")
42
  ],
43
- outputs=gr.Image(label="Generated Image"),
44
  title="Pony Image Generator API"
45
  )
46
 
 
1
  import gradio as gr
2
  from huggingface_hub import hf_hub_download
3
+ from diffusers import StableDiffusionPipeline
4
+ import torch
5
  import os
 
 
6
 
7
+ print("Downloading model...")
8
  model_path = hf_hub_download(
9
  repo_id="calcuis/pony",
10
  filename="blackmagic-q4_k_m.gguf",
 
12
  )
13
  print(f"Model ready at: {model_path}")
14
 
15
+ print("Loading pipeline...")
16
+ pipe = StableDiffusionPipeline.from_single_file(
17
+ model_path,
18
+ torch_dtype=torch.float32,
19
+ )
20
+ pipe.to("cpu")
21
+ print("Pipeline ready!")
22
+
23
+ def generate(prompt, negative_prompt="bad quality, blurry", steps=5):
24
+ print(f"Generating: {prompt}")
25
+ image = pipe(
26
+ prompt=prompt,
27
+ negative_prompt=negative_prompt,
28
+ num_inference_steps=int(steps),
29
+ height=512,
30
+ width=512,
31
+ ).images[0]
32
+ print("Done!")
33
+ return image
 
 
34
 
35
  demo = gr.Interface(
36
  fn=generate,
37
  inputs=[
38
  gr.Textbox(label="Prompt", value="a cute cat sitting on a bench"),
39
  gr.Textbox(label="Negative Prompt", value="bad quality, blurry"),
40
+ gr.Slider(minimum=1, maximum=30, value=5, step=1, label="Steps")
41
  ],
42
+ outputs=gr.Image(label="Generated Image", type="pil"),
43
  title="Pony Image Generator API"
44
  )
45