Spaces:
Runtime error
Runtime error
freemt
commited on
Commit
·
094f795
1
Parent(s):
9a87834
Update multimodalart/latentdiffusion
Browse files- app.py +44 -2
- requirements.txt +2 -0
app.py
CHANGED
@@ -1,5 +1,8 @@
|
|
1 |
"""See https://huggingface.co/spaces/Gradio-Blocks/Story-to-video/blob/main/app.py."""
|
2 |
import gradio as gr
|
|
|
|
|
|
|
3 |
|
4 |
# from PIL import Image
|
5 |
# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
|
@@ -8,6 +11,45 @@ import gradio as gr
|
|
8 |
|
9 |
image_gen = gr.Interface.load("spaces/multimodalart/latentdiffusion")
|
10 |
|
11 |
-
# image_bytes = image_gen(senten, steps, width, height, num_images, diversity)
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
"""See https://huggingface.co/spaces/Gradio-Blocks/Story-to-video/blob/main/app.py."""
|
2 |
import gradio as gr
|
3 |
+
import base64
|
4 |
+
import io
|
5 |
+
from PIL import Image # opencv-python
|
6 |
|
7 |
# from PIL import Image
|
8 |
# from transformers import AutoTokenizer, AutoModelForSeq2SeqLM,pipeline
|
|
|
11 |
|
12 |
image_gen = gr.Interface.load("spaces/multimodalart/latentdiffusion")
|
13 |
|
|
|
14 |
|
15 |
+
def generate_images(phrase: str):
|
16 |
+
generated_text = phrase
|
17 |
+
steps = 125
|
18 |
+
width = 256
|
19 |
+
height = 256
|
20 |
+
num_images = 4
|
21 |
+
num_images = 1
|
22 |
+
diversity = 6
|
23 |
+
|
24 |
+
image_bytes = image_gen(generated_text, steps, width, height, num_images, diversity)
|
25 |
+
|
26 |
+
# Algo from spaces/Gradio-Blocks/latent_gpt2_story/blob/main/app.py
|
27 |
+
# generated_images = []
|
28 |
+
|
29 |
+
img = None
|
30 |
+
for image in image_bytes[1]:
|
31 |
+
image_str = image[0]
|
32 |
+
try:
|
33 |
+
image_str = image_str.replace("data:image/png;base64,", "")
|
34 |
+
except Exception as exc:
|
35 |
+
logger.error(exc)
|
36 |
+
return None
|
37 |
+
decoded_bytes = base64.decodebytes(bytes(image_str, "utf-8"))
|
38 |
+
img = Image.open(io.BytesIO(decoded_bytes))
|
39 |
+
|
40 |
+
# generated_images.append(img)
|
41 |
+
|
42 |
+
# return generated_images
|
43 |
+
return img
|
44 |
+
|
45 |
+
|
46 |
+
examples = ["an apple", "Donald Trump"]
|
47 |
+
|
48 |
+
iface = gr.Interface(
|
49 |
+
generate_images,
|
50 |
+
"text",
|
51 |
+
"image",
|
52 |
+
examples=examples,
|
53 |
+
)
|
54 |
+
|
55 |
+
iface.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
logzero
|
2 |
+
opencv-python
|