Dagfinn1962 commited on
Commit
dec9f9f
β€’
1 Parent(s): ac621bf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -1,20 +1,24 @@
1
  from diffusers import StableDiffusionXLPipeline
2
  import torch
 
3
  import gradio as gr
 
4
 
5
- # Load the model with forced download
6
  model_id = "RunDiffusion/Juggernaut-X-v10"
7
- pipe = StableDiffusionXLPipeline.from_pretrained(model_id, torch_dtype=torch.float32, force_download=True)
8
- pipe = pipe.to("cpu")
9
 
10
- def text_to_image(prompt, negative_prompt, steps, guidance_scale, add_4k_masterpiece):
 
11
  if add_4k_masterpiece:
12
  prompt += ", 4k, (masterpiece)"
13
  image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, guidance_scale=guidance_scale).images[0]
14
  return image
 
15
 
16
- gradio_interface = gr.Interface(
17
  fn=text_to_image,
 
18
  inputs=[
19
  gr.Textbox(label="Prompt", lines=2, placeholder="Enter your prompt here..."),
20
  gr.Textbox(label="Negative Prompt", lines=2, placeholder="What to exclude from the image..."),
@@ -22,13 +26,11 @@ gradio_interface = gr.Interface(
22
  gr.Slider(minimum=1, maximum=20, value=7.5, label="Guidance Scale", step=0.1),
23
  gr.Checkbox(label="Add recommended prompt items (4k, masterpiece)", value=False)
24
  ],
25
- outputs=gr.Image(type="pil", show_download_button=True),
26
  examples=[
27
- [" hyper realistic , detailed , real person , very pretty naked Japanese 18 yo girl, looking at the viewer, ashamed, (smile:0.7), textured fair skin, tight skirt, She is standing up in an open-air bath in a Japanese hot spring, medium breasts , skinny but fit , 8k , Leica quality , masterpiece , , 4k, high quality, (masterpiece)", "worst quality, low quality, bad anatomy, bad hands, missing fingers, fewer digits, source_furry, source_pony, source_cartoon,3d, blurry,", 60, 9.5, False],
28
  ],
29
  cache_examples=False,
30
  theme=gr.themes.Soft()
31
  )
32
-
33
- # Launch the Gradio app with share=True
34
  gradio_interface.launch()
 
1
  from diffusers import StableDiffusionXLPipeline
2
  import torch
3
+ from gradio import Interface, Image, Dropdown, Slider
4
  import gradio as gr
5
+ import spaces
6
 
 
7
  model_id = "RunDiffusion/Juggernaut-X-v10"
8
+ pipe = StableDiffusionXLPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
9
+ pipe = pipe.to("cuda")
10
 
11
+ @spaces.GPU()
12
+ def text_to_image(prompt, negative_prompt, steps, guidance_scale, add_4k_masterpiece, progress=gr.Progress(track_tqdm=True)):
13
  if add_4k_masterpiece:
14
  prompt += ", 4k, (masterpiece)"
15
  image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=steps, guidance_scale=guidance_scale).images[0]
16
  return image
17
+ duplicate_button = gr.DuplicateButton(value="Duplicate Space for private use", elem_id="duplicate-button")
18
 
19
+ gradio_interface = Interface(
20
  fn=text_to_image,
21
+ allow_duplication=True,
22
  inputs=[
23
  gr.Textbox(label="Prompt", lines=2, placeholder="Enter your prompt here..."),
24
  gr.Textbox(label="Negative Prompt", lines=2, placeholder="What to exclude from the image..."),
 
26
  gr.Slider(minimum=1, maximum=20, value=7.5, label="Guidance Scale", step=0.1),
27
  gr.Checkbox(label="Add recommended prompt items (4k, masterpiece)", value=False)
28
  ],
29
+ outputs=Image(type="pil", show_download_button=True),
30
  examples=[
31
+ ["very pretty naked Japanese 18 yo girl, looking at the viewer, ashamed, (smile:0.7), textured fair skin, perfect teen body, medium breasts"],
32
  ],
33
  cache_examples=False,
34
  theme=gr.themes.Soft()
35
  )
 
 
36
  gradio_interface.launch()