Spaces:
Runtime error
Runtime error
File size: 1,454 Bytes
4c80b26 |
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 |
# + tags=["hide_inp"]
desc = """
### Gradio Tool
Examples using the gradio tool [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/srush/MiniChain/blob/master/examples/gradio_example.ipynb)
"""
# -
# $
from minichain import show, prompt, OpenAI, OpenAIStream
import gradio as gr
from gradio_tools.tools import StableDiffusionTool, ImageCaptioningTool
@prompt(OpenAIStream(), stream=True)
def picture(model, query):
out = ""
for r in model.stream(query):
out += r
yield out
@prompt(StableDiffusionTool(), stream=True, block_input=lambda: gr.Textbox(label=""))
def gen(model, query):
for r in model.stream(query):
yield "https://htmlcolorcodes.com/assets/images/colors/baby-blue-color-solid-background-1920x1080.png"
yield r
@prompt(ImageCaptioningTool(), block_output=lambda: gr.Textbox(label=""))
def caption(model, img_src):
return model(img_src)
def gradio_example(query):
return caption(gen(picture(query)))
# $
gradio = show(gradio_example,
subprompts=[picture, gen, caption],
examples=['Describe a one-sentence fantasy scene.',
'Describe a one-sentence scene happening on the moon.'],
out_type="markdown",
description=desc,
css="#advanced {display: none}"
)
if __name__ == "__main__":
gradio.queue().launch()
|