Spaces:
Sleeping
Sleeping
Commit
β’
7b0566a
1
Parent(s):
9c46072
Upload folder using huggingface_hub
Browse files- demos/calculator/run.py +4 -13
- demos/chatbot_multimodal/run.py +9 -8
- demos/chatinterface_streaming_echo/run.py +1 -1
- demos/fake_diffusion_with_gif/run.py +47 -29
- requirements.txt +2 -2
demos/calculator/run.py
CHANGED
@@ -1,16 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
from foo import foo_fn
|
5 |
-
|
6 |
-
with gr.no_reload():
|
7 |
-
print("HERE")
|
8 |
-
print("FOO BAR")
|
9 |
-
import numpy as np
|
10 |
-
|
11 |
def calculator(num1, operation, num2):
|
12 |
-
print("foo_fn", foo_fn())
|
13 |
-
print(np.zeros(10))
|
14 |
if operation == "add":
|
15 |
return num1 + num2
|
16 |
elif operation == "subtract":
|
@@ -26,7 +17,7 @@ demo = gr.Interface(
|
|
26 |
calculator,
|
27 |
[
|
28 |
"number",
|
29 |
-
gr.Radio(["add", "subtract", "multiply", "divide"]
|
30 |
"number"
|
31 |
],
|
32 |
"number",
|
@@ -36,7 +27,7 @@ demo = gr.Interface(
|
|
36 |
[144, "multiply", 2.5],
|
37 |
[0, "subtract", 1.2],
|
38 |
],
|
39 |
-
title="Toy Calculator
|
40 |
description="Here's a sample toy calculator. Allows you to calculate things like $2+2=4$",
|
41 |
)
|
42 |
|
|
|
1 |
import gradio as gr
|
2 |
+
#from foo import BAR
|
3 |
+
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
def calculator(num1, operation, num2):
|
|
|
|
|
5 |
if operation == "add":
|
6 |
return num1 + num2
|
7 |
elif operation == "subtract":
|
|
|
17 |
calculator,
|
18 |
[
|
19 |
"number",
|
20 |
+
gr.Radio(["add", "subtract", "multiply", "divide"]),
|
21 |
"number"
|
22 |
],
|
23 |
"number",
|
|
|
27 |
[144, "multiply", 2.5],
|
28 |
[0, "subtract", 1.2],
|
29 |
],
|
30 |
+
title="Toy Calculator",
|
31 |
description="Here's a sample toy calculator. Allows you to calculate things like $2+2=4$",
|
32 |
)
|
33 |
|
demos/chatbot_multimodal/run.py
CHANGED
@@ -9,15 +9,16 @@ def print_like_dislike(x: gr.LikeData):
|
|
9 |
print(x.index, x.value, x.liked)
|
10 |
|
11 |
|
12 |
-
def add_text(history, text
|
13 |
-
|
14 |
-
msg = f"<img src='/file={image}' /> {text}"
|
15 |
-
else:
|
16 |
-
msg = txt
|
17 |
-
history = history + [(msg, None)]
|
18 |
return history, gr.Textbox(value="", interactive=False)
|
19 |
|
20 |
|
|
|
|
|
|
|
|
|
|
|
21 |
def bot(history):
|
22 |
response = "**That's cool!**"
|
23 |
history[-1][1] = ""
|
@@ -44,11 +45,11 @@ with gr.Blocks() as demo:
|
|
44 |
)
|
45 |
btn = gr.UploadButton("π", file_types=["image", "video", "audio"])
|
46 |
|
47 |
-
txt_msg = txt.submit(add_text, [chatbot, txt
|
48 |
bot, chatbot, chatbot, api_name="bot_response"
|
49 |
)
|
50 |
txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
|
51 |
-
file_msg = btn.upload(
|
52 |
bot, chatbot, chatbot
|
53 |
)
|
54 |
|
|
|
9 |
print(x.index, x.value, x.liked)
|
10 |
|
11 |
|
12 |
+
def add_text(history, text):
|
13 |
+
history = history + [(text, None)]
|
|
|
|
|
|
|
|
|
14 |
return history, gr.Textbox(value="", interactive=False)
|
15 |
|
16 |
|
17 |
+
def add_file(history, file):
|
18 |
+
history = history + [((file.name,), None)]
|
19 |
+
return history
|
20 |
+
|
21 |
+
|
22 |
def bot(history):
|
23 |
response = "**That's cool!**"
|
24 |
history[-1][1] = ""
|
|
|
45 |
)
|
46 |
btn = gr.UploadButton("π", file_types=["image", "video", "audio"])
|
47 |
|
48 |
+
txt_msg = txt.submit(add_text, [chatbot, txt], [chatbot, txt], queue=False).then(
|
49 |
bot, chatbot, chatbot, api_name="bot_response"
|
50 |
)
|
51 |
txt_msg.then(lambda: gr.Textbox(interactive=True), None, [txt], queue=False)
|
52 |
+
file_msg = btn.upload(add_file, [chatbot, btn], [chatbot], queue=False).then(
|
53 |
bot, chatbot, chatbot
|
54 |
)
|
55 |
|
demos/chatinterface_streaming_echo/run.py
CHANGED
@@ -11,4 +11,4 @@ def slow_echo(message, history):
|
|
11 |
demo = gr.ChatInterface(slow_echo).queue()
|
12 |
|
13 |
if __name__ == "__main__":
|
14 |
-
demo.launch(
|
|
|
11 |
demo = gr.ChatInterface(slow_echo).queue()
|
12 |
|
13 |
if __name__ == "__main__":
|
14 |
+
demo.launch()
|
demos/fake_diffusion_with_gif/run.py
CHANGED
@@ -1,31 +1,49 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
import os
|
|
|
|
|
|
|
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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import time
|
4 |
import os
|
5 |
+
from PIL import Image
|
6 |
+
import requests
|
7 |
+
from io import BytesIO
|
8 |
|
9 |
+
|
10 |
+
def create_gif(images):
|
11 |
+
pil_images = []
|
12 |
+
for image in images:
|
13 |
+
if isinstance(image, str):
|
14 |
+
response = requests.get(image)
|
15 |
+
image = Image.open(BytesIO(response.content))
|
16 |
+
else:
|
17 |
+
image = Image.fromarray((image * 255).astype(np.uint8))
|
18 |
+
pil_images.append(image)
|
19 |
+
fp_out = os.path.join(os.path.dirname(__file__), "image.gif")
|
20 |
+
img = pil_images.pop(0)
|
21 |
+
img.save(fp=fp_out, format='GIF', append_images=pil_images,
|
22 |
+
save_all=True, duration=400, loop=0)
|
23 |
+
return fp_out
|
24 |
+
|
25 |
+
|
26 |
+
def fake_diffusion(steps):
|
27 |
+
rng = np.random.default_rng()
|
28 |
+
images = []
|
29 |
+
for _ in range(steps):
|
30 |
+
time.sleep(1)
|
31 |
+
image = rng.random((600, 600, 3))
|
32 |
+
images.append(image)
|
33 |
+
yield image, gr.Image(visible=False)
|
34 |
+
|
35 |
+
time.sleep(1)
|
36 |
+
image = "https://gradio-builds.s3.amazonaws.com/diffusion_image/cute_dog.jpg"
|
37 |
+
images.append(image)
|
38 |
+
gif_path = create_gif(images)
|
39 |
+
|
40 |
+
yield image, gr.Image(value=gif_path, visible=True)
|
41 |
+
|
42 |
+
|
43 |
+
demo = gr.Interface(fake_diffusion,
|
44 |
+
inputs=gr.Slider(1, 10, 3, step=1),
|
45 |
+
outputs=["image", gr.Image(label="All Images", visible=False)])
|
46 |
+
demo.queue()
|
47 |
+
|
48 |
+
if __name__ == "__main__":
|
49 |
+
demo.launch()
|
requirements.txt
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
|
2 |
-
gradio-client @ git+https://github.com/gradio-app/gradio@
|
3 |
-
https://gradio-builds.s3.amazonaws.com/
|
4 |
pypistats==1.1.0
|
5 |
plotly==5.10.0
|
6 |
opencv-python==4.6.0.66
|
|
|
1 |
|
2 |
+
gradio-client @ git+https://github.com/gradio-app/gradio@556dff3e7dea0d40d9a15571a9ea6031b1ac7e71#subdirectory=client/python
|
3 |
+
https://gradio-builds.s3.amazonaws.com/556dff3e7dea0d40d9a15571a9ea6031b1ac7e71/gradio-4.21.0-py3-none-any.whl
|
4 |
pypistats==1.1.0
|
5 |
plotly==5.10.0
|
6 |
opencv-python==4.6.0.66
|