radames commited on
Commit
5a8c0f6
·
1 Parent(s): d7fc5d3

gradio slide

Browse files
Files changed (2) hide show
  1. app.py +29 -20
  2. requirements.txt +2 -1
app.py CHANGED
@@ -1,6 +1,8 @@
1
 
2
  import gradio as gr
3
  from PIL import Image
 
 
4
  import requests
5
  import base64
6
  import numpy as np
@@ -22,6 +24,7 @@ def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
22
 
23
 
24
  def generate(
 
25
  prompt: str,
26
  negative_prompt: str = "",
27
  seed: int = 0,
@@ -39,9 +42,9 @@ def generate(
39
  payload = {
40
  "input": {
41
  "hdr": 0,
42
- "image": "https://replicate.delivery/pbxt/KA9yP9n3ZX5A5mkoPz3gsPzKTH1NA7LqVkQRTg7Sov46lOfo/0_1.webp",
43
  "steps": 20,
44
- "prompt": "UHD 4k vogue, a woman resting in a magic pool, face above the surface of the water, red freckles",
45
  "scheduler": "DDIM",
46
  "creativity": 0.25,
47
  "guess_mode": False,
@@ -58,29 +61,34 @@ def generate(
58
  image_data = base64.b64decode(
59
  base64_image.replace("data:image/png;base64,", ""))
60
  image_stream = io.BytesIO(image_data)
61
- return Image.open(image_stream)
62
  raise gr.Error(json_response["status"])
63
 
64
 
65
  examples = [
66
- "An astronaut riding a green horse",
67
- "A mecha robot in a favela by Tarsila do Amaral",
68
- "The sprirt of a Tamagotchi wandering in the city of Los Angeles",
69
- "A delicious feijoada ramen dish"
 
70
  ]
71
 
72
  with gr.Blocks() as demo:
73
- with gr.Group():
74
- with gr.Row():
75
- prompt = gr.Text(
76
- label="Prompt",
77
- show_label=False,
78
- max_lines=1,
79
- placeholder="Enter your prompt",
80
- container=False,
81
- )
82
- run_button = gr.Button("Run", scale=0)
83
- result = gr.Image(label="Result", show_label=False)
 
 
 
 
84
  with gr.Accordion("Advanced options", open=False):
85
  negative_prompt = gr.Text(
86
  label="Negative prompt",
@@ -151,13 +159,14 @@ with gr.Blocks() as demo:
151
 
152
  gr.Examples(
153
  examples=examples,
154
- inputs=prompt,
155
  outputs=result,
156
  fn=generate,
157
- cache_examples=False,
158
  )
159
 
160
  inputs = [
 
161
  prompt,
162
  negative_prompt,
163
  seed,
 
1
 
2
  import gradio as gr
3
  from PIL import Image
4
+ from gradio_imageslider import ImageSlider
5
+
6
  import requests
7
  import base64
8
  import numpy as np
 
24
 
25
 
26
  def generate(
27
+ input_image: Image,
28
  prompt: str,
29
  negative_prompt: str = "",
30
  seed: int = 0,
 
42
  payload = {
43
  "input": {
44
  "hdr": 0,
45
+ "image": "http://localhost:7860/file=" + input_image,
46
  "steps": 20,
47
+ "prompt": prompt,
48
  "scheduler": "DDIM",
49
  "creativity": 0.25,
50
  "guess_mode": False,
 
61
  image_data = base64.b64decode(
62
  base64_image.replace("data:image/png;base64,", ""))
63
  image_stream = io.BytesIO(image_data)
64
+ return [Image.open(input_image), Image.open(image_stream)]
65
  raise gr.Error(json_response["status"])
66
 
67
 
68
  examples = [
69
+ ["An astronaut riding a green horse", "examples/image2.png"],
70
+ ["A mecha robot in a favela by Tarsila do Amaral", "examples/image2.png"],
71
+ ["The sprirt of a Tamagotchi wandering in the city of Los Angeles",
72
+ "examples/image1.png"],
73
+ ["A delicious feijoada ramen dish", "examples/image0.png"],
74
  ]
75
 
76
  with gr.Blocks() as demo:
77
+ with gr.Row():
78
+ with gr.Column():
79
+ input_image = gr.Image(type="filepath")
80
+ with gr.Group():
81
+ with gr.Row():
82
+ prompt = gr.Text(
83
+ label="Prompt",
84
+ show_label=False,
85
+ max_lines=1,
86
+ placeholder="Enter your prompt",
87
+ container=False,
88
+ )
89
+ run_button = gr.Button("Run", scale=0)
90
+ with gr.Column():
91
+ result = ImageSlider(label="Result", type="pil")
92
  with gr.Accordion("Advanced options", open=False):
93
  negative_prompt = gr.Text(
94
  label="Negative prompt",
 
159
 
160
  gr.Examples(
161
  examples=examples,
162
+ inputs=[prompt, input_image],
163
  outputs=result,
164
  fn=generate,
165
+ cache_examples=True,
166
  )
167
 
168
  inputs = [
169
+ input_image,
170
  prompt,
171
  negative_prompt,
172
  seed,
requirements.txt CHANGED
@@ -1,2 +1,3 @@
1
  gradio==4.18.0
2
- replicate==0.23.1
 
 
1
  gradio==4.18.0
2
+ replicate==0.23.1
3
+ gradio_imageslider==0.0.17