CoolFace
Apppublic

Sacso/FlowerDi

sourceHugging Faceupdated 4y agoView on Hugging Face
1likes
app.py72 linesDownload Raw Back to root
1import io2import os3import warnings4 5from PIL import Image6from stability_sdk import client7import stability_sdk.interfaces.gooseai.generation.generation_pb2 as generation8 9import gradio as gr10stability_api = client.StabilityInference(11    key=os.environ["Secret"], 12    verbose=True,13)14 15 16def infer(prompt):17  # the object returned is a python generator18  answers = stability_api.generate(19      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",20      height =64021  )22  23  # iterating over the generator produces the api response24  for resp in answers:25      for artifact in resp.artifacts:26          if artifact.finish_reason == generation.FILTER:27              warnings.warn(28                  "Your request activated the API's safety filters and could not be processed."29                  "Please modify the prompt and try again.")30          if artifact.type == generation.ARTIFACT_IMAGE:31              img = Image.open(io.BytesIO(artifact.binary))32              return img33 34 35block = gr.Blocks(css=".container { max-width: 600px; margin: auto; }")36 37num_samples = 138 39 40 41with block as demo:42    gr.Markdown("<h1><center>Flower Diffusion</center></h1>")43    gr.Markdown(44        "Get a pretty flowery image from any prompt - keep it simple!"45    )46    with gr.Group():47        with gr.Box():48            with gr.Row().style(mobile_collapse=False, equal_height=True):49 50                text = gr.Textbox(51                value = "Kitty cat",52                    label="Enter your prompt", show_label=False, max_lines=153                ).style(54                    border=(True, False, True, True),55                    rounded=(True, False, False, True),56                    container=False,57                )58                btn = gr.Button("Run").style(59                    margin=False,60                    rounded=(False, True, True, False),61                )62        63               64        gallery = gr.Image()65        text.submit(infer, inputs=[text], outputs=gallery)66        btn.click(infer, inputs=[text], outputs=gallery)67 68   69    70 71 72demo.launch(debug=True, enable_queue = True)