File size: 2,235 Bytes
841be4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2f0e820
9b9725a
841be4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cfb5815
841be4d
cfb5815
841be4d
 
 
 
 
 
63779d2
841be4d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5659063
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import io
import os
import warnings

from PIL import Image
from stability_sdk import client
import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation

import gradio as gr
stability_api = client.StabilityInference(
    key=os.environ["Secret"], 
    verbose=True,
)


def infer(prompt):
  # the object returned is a python generator
  answers = stability_api.generate(
      prompt=f"Beautiful Portait of a {prompt} made out of flowers 💐 🌺 🌸 , artstation winner by Victo Ngai, Kilian Eng, vibrant colors, winning-award masterpiece, aesthetic octane render, 8K HD",
      height =640
  )
  
  # iterating over the generator produces the api response
  for resp in answers:
      for artifact in resp.artifacts:
          if artifact.finish_reason == generation.FILTER:
              warnings.warn(
                  "Your request activated the API's safety filters and could not be processed."
                  "Please modify the prompt and try again.")
          if artifact.type == generation.ARTIFACT_IMAGE:
              img = Image.open(io.BytesIO(artifact.binary))
              return img


block = gr.Blocks(css=".container { max-width: 600px; margin: auto; }")

num_samples = 1



with block as demo:
    gr.Markdown("<h1><center>Flower Diffusion</center></h1>")
    gr.Markdown(
        "Get a pretty flowery image from any prompt - keep it simple!"
    )
    with gr.Group():
        with gr.Box():
            with gr.Row().style(mobile_collapse=False, equal_height=True):

                text = gr.Textbox(
                value = "Kitty cat",
                    label="Enter your prompt", show_label=False, max_lines=1
                ).style(
                    border=(True, False, True, True),
                    rounded=(True, False, False, True),
                    container=False,
                )
                btn = gr.Button("Run").style(
                    margin=False,
                    rounded=(False, True, True, False),
                )
        
               
        gallery = gr.Image()
        text.submit(infer, inputs=[text], outputs=gallery)
        btn.click(infer, inputs=[text], outputs=gallery)

   
    


demo.launch(debug=True, enable_queue = True)