Wilbur1240 commited on
Commit
396eb0c
·
1 Parent(s): 0663246

update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -5
app.py CHANGED
@@ -1,12 +1,55 @@
1
  import gradio as gr
 
 
 
 
2
 
3
- def infer(prompt):
4
- return f"Hello from: {prompt}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  demo = gr.Interface(
7
  fn=infer,
8
- inputs=gr.Textbox(label="Enter something"),
9
- outputs=gr.Textbox(label="Output")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  )
11
 
12
- demo.launch(show_api=False)
 
1
  import gradio as gr
2
+ import numpy as np
3
+ import random
4
+ from huggingface_hub import InferenceClient
5
+ import os
6
 
7
+ MAX_SEED = np.iinfo(np.int32).max
8
+ MAX_IMAGE_SIZE = 1024
9
+
10
+ client = InferenceClient(
11
+ provider="hf-inference",
12
+ api_key=os.environ["HF_API_TOKEN"]
13
+ )
14
+
15
+ def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
16
+ if randomize_seed:
17
+ seed = random.randint(0, MAX_SEED)
18
+
19
+ image = client.text_to_image(
20
+ prompt=prompt,
21
+ model="stabilityai/sdxl-turbo",
22
+ negative_prompt=negative_prompt,
23
+ guidance_scale=guidance_scale,
24
+ num_inference_steps=num_inference_steps,
25
+ width=width,
26
+ height=height,
27
+ seed=seed,
28
+ )
29
+ return image, seed
30
 
31
  demo = gr.Interface(
32
  fn=infer,
33
+ inputs=[
34
+ gr.Textbox(label="Prompt"),
35
+ gr.Textbox(label="Negative Prompt", value=""),
36
+ gr.Slider(0, MAX_SEED, label="Seed", value=0),
37
+ gr.Checkbox(label="Randomize Seed", value=True),
38
+ gr.Slider(256, MAX_IMAGE_SIZE, label="Width", step=32, value=768),
39
+ gr.Slider(256, MAX_IMAGE_SIZE, label="Height", step=32, value=768),
40
+ gr.Slider(0, 10, label="Guidance Scale", step=0.1, value=0.0),
41
+ gr.Slider(1, 50, label="Steps", step=1, value=2)
42
+ ],
43
+ outputs=[
44
+ gr.Image(label="Generated Image"),
45
+ gr.Number(label="Seed Used")
46
+ ],
47
+ examples=[
48
+ ["A futuristic cityscape at sunset", "", 0, True, 768, 768, 0.0, 2],
49
+ ["A cat in a space suit", "", 0, True, 768, 768, 0.0, 2],
50
+ ],
51
+ title="SDXL Turbo Text-to-Image",
52
+ allow_flagging="never"
53
  )
54
 
55
+ demo.launch(show_api=False)