Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,20 +1,29 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from
|
| 4 |
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
print(f"string -- {tmp}")
|
| 14 |
-
print(f"Path(__file__) - {Path(__file__)}")
|
| 15 |
-
with gr.Blocks() as demo:
|
| 16 |
-
img = gr.Image(value= tmp, type='filepath')
|
| 17 |
-
img = gr.Image(value= tmp1, type='filepath')
|
| 18 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import tempfile
|
| 3 |
+
from PIL import Image
|
| 4 |
|
| 5 |
+
def create():
|
| 6 |
+
color='blue'
|
| 7 |
+
width=512
|
| 8 |
+
height=512
|
| 9 |
|
| 10 |
+
# Create a temporary file
|
| 11 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
| 12 |
+
print(f"Temporary file created at: {temp_file.name}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
+
# Create a new image with the given mode and size
|
| 15 |
+
image = Image.new("RGB", (width, height), color)
|
| 16 |
+
|
| 17 |
+
# Save the image to disk
|
| 18 |
+
image.save(temp_file, format='PNG')
|
| 19 |
+
|
| 20 |
+
return temp_file.name
|
| 21 |
|
| 22 |
+
# usage:
|
| 23 |
+
|
| 24 |
+
with gr.Blocks(delete_cache=(2,4)) as demo:
|
| 25 |
+
out = gr.Image(type='filepath')
|
| 26 |
+
btn = gr.Button("GO!")
|
| 27 |
+
btn.click(create,inputs=[],outputs=out)
|
| 28 |
+
|
| 29 |
demo.launch()
|