ysharma HF Staff commited on
Commit
9f34051
·
verified ·
1 Parent(s): 567e493

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -1,20 +1,29 @@
1
  import gradio as gr
2
- import os
3
- from pathlib import Path
4
 
5
- proj_dir1 = Path.cwd()
6
- print(f"proj_dir1 -- {proj_dir1}")
7
- tmp1 = str(proj_dir1 / 'media' / 'banner.png')
8
- print(f"string1 -- {tmp1}")
9
 
10
- proj_dir2 = Path(__file__).parent
11
- print(f"proj_dir -- {proj_dir2}")
12
- tmp = str(proj_dir2 / 'media' / 'banner.png')
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()