srush HF staff commited on
Commit
4c80b26
·
1 Parent(s): 1a44555

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # + tags=["hide_inp"]
2
+
3
+ desc = """
4
+ ### Gradio Tool
5
+
6
+ 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)
7
+
8
+ """
9
+ # -
10
+
11
+ # $
12
+
13
+ from minichain import show, prompt, OpenAI, OpenAIStream
14
+ import gradio as gr
15
+ from gradio_tools.tools import StableDiffusionTool, ImageCaptioningTool
16
+
17
+ @prompt(OpenAIStream(), stream=True)
18
+ def picture(model, query):
19
+ out = ""
20
+ for r in model.stream(query):
21
+ out += r
22
+ yield out
23
+
24
+ @prompt(StableDiffusionTool(), stream=True, block_input=lambda: gr.Textbox(label=""))
25
+ def gen(model, query):
26
+ for r in model.stream(query):
27
+ yield "https://htmlcolorcodes.com/assets/images/colors/baby-blue-color-solid-background-1920x1080.png"
28
+ yield r
29
+
30
+ @prompt(ImageCaptioningTool(), block_output=lambda: gr.Textbox(label=""))
31
+ def caption(model, img_src):
32
+ return model(img_src)
33
+
34
+ def gradio_example(query):
35
+ return caption(gen(picture(query)))
36
+
37
+
38
+ # $
39
+
40
+ gradio = show(gradio_example,
41
+ subprompts=[picture, gen, caption],
42
+ examples=['Describe a one-sentence fantasy scene.',
43
+ 'Describe a one-sentence scene happening on the moon.'],
44
+ out_type="markdown",
45
+ description=desc,
46
+ css="#advanced {display: none}"
47
+
48
+ )
49
+ if __name__ == "__main__":
50
+ gradio.queue().launch()
51
+