Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tempfile
|
3 |
+
from PIL import Image
|
4 |
+
import os
|
5 |
+
|
6 |
+
# Access the environment variable
|
7 |
+
print(os.environ['GRADIO_TEMP_DIR'])
|
8 |
+
|
9 |
+
def create():
|
10 |
+
"""
|
11 |
+
Create a blank image with the specified dimensions, color, and filename.
|
12 |
+
"""
|
13 |
+
color='blue'
|
14 |
+
width=512
|
15 |
+
height=512
|
16 |
+
# Create a temporary file
|
17 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
|
18 |
+
print(f"Temporary file created at: {temp_file.name}")
|
19 |
+
#filename = f'{temp_file.name}.png'
|
20 |
+
# Create a new image with the given mode and size
|
21 |
+
image = Image.new("RGB", (width, height), color)
|
22 |
+
# Save the image to disk
|
23 |
+
image.save(temp_file, format='PNG')
|
24 |
+
return temp_file.name
|
25 |
+
|
26 |
+
|
27 |
+
with gr.Blocks(delete_cache=(2,2),
|
28 |
+
theme=gr.themes.Base(radius_size="none")) as demo:
|
29 |
+
with gr.Row():
|
30 |
+
inp = gr.Textbox(placeholder="What is your name?")
|
31 |
+
out = gr.Image(type='filepath')
|
32 |
+
btn = gr.Button("GO!")
|
33 |
+
btn.click(create,inputs=[],outputs=out)
|
34 |
+
|
35 |
+
demo.launch(debug=False)
|