Spaces:
Runtime error
[Feature] Add User history
Browse filesThis PR adds a _User History_ feature:
- **Past generations** are saved and accessible in a separate section. Users can see all the images they've already generated.
- **metadata** are saved for each image (prompt, pipeline, timestamp,...)
- Images and metadata can be **exported** by the user
- A **delete** button allows the user to delete their history for privacy reason
- An **admin panel** shows how many images have being generated and saved, by how many users and how much storage is left (only accessible to Space owners).
**For optimal UX, a Persistent Storage must be attached to the Space**. If it's not case, the user history will still work but images will be lost when Space restarts. A disclaimer warns the user to export their creation to save them properly.
[Here is a demo Space](https://huggingface.co/spaces/Wauplin/gradio-user-history) showcasing the _User History_ feature. You can also find it on popular Spaces like [AP123/IllusionDiffusion](https://huggingface.co/spaces/AP123/IllusionDiffusion) and [warp-ai/Wuerstchen](https://huggingface.co/spaces/warp-ai/Wuerstchen).
Please let me know if you have any questions!
### Preview:
_(Wurstchen Space)_

|
@@ -4,7 +4,7 @@ import torch
|
|
| 4 |
|
| 5 |
from diffusers import DiffusionPipeline
|
| 6 |
from free_lunch_utils import register_free_upblock2d, register_free_crossattn_upblock2d
|
| 7 |
-
|
| 8 |
|
| 9 |
|
| 10 |
model_id = "stabilityai/stable-diffusion-2-1"
|
|
@@ -21,7 +21,7 @@ sd_options_prev = None
|
|
| 21 |
seed_prev = None
|
| 22 |
sd_image_prev = None
|
| 23 |
|
| 24 |
-
def infer(prompt, sd_options, seed, b1, b2, s1, s2):
|
| 25 |
global prompt_prev
|
| 26 |
global sd_options_prev
|
| 27 |
global seed_prev
|
|
@@ -65,6 +65,9 @@ def infer(prompt, sd_options, seed, b1, b2, s1, s2):
|
|
| 65 |
# First SD, then freeu
|
| 66 |
images = [sd_image, freeu_image]
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
return images
|
| 69 |
|
| 70 |
|
|
@@ -209,7 +212,12 @@ with block:
|
|
| 209 |
maximum=1000,
|
| 210 |
step=1,
|
| 211 |
value=42)
|
| 212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
with gr.Row():
|
| 214 |
with gr.Group():
|
| 215 |
# btn = gr.Button("Generate image", scale=0)
|
|
|
|
| 4 |
|
| 5 |
from diffusers import DiffusionPipeline
|
| 6 |
from free_lunch_utils import register_free_upblock2d, register_free_crossattn_upblock2d
|
| 7 |
+
import gradio_user_history as gr_user_history
|
| 8 |
|
| 9 |
|
| 10 |
model_id = "stabilityai/stable-diffusion-2-1"
|
|
|
|
| 21 |
seed_prev = None
|
| 22 |
sd_image_prev = None
|
| 23 |
|
| 24 |
+
def infer(prompt, sd_options, seed, b1, b2, s1, s2, profile: gr.OAuthProfile | None):
|
| 25 |
global prompt_prev
|
| 26 |
global sd_options_prev
|
| 27 |
global seed_prev
|
|
|
|
| 65 |
# First SD, then freeu
|
| 66 |
images = [sd_image, freeu_image]
|
| 67 |
|
| 68 |
+
gr_user_history.save_image(label=prompt + ' (SD)', image=sd_image, profile=profile, metadata={"prompt": prompt, "pipe": sd_options, "b1": 1.0, "b2": 1.0, "s1": 1.0, "s2": 1.0})
|
| 69 |
+
gr_user_history.save_image(label=prompt + ' (FreeU)', image=freeu_image, profile=profile, metadata={"prompt": prompt, "pipe": "freeu", "b1": b1, "b2": b2, "s1": s1, "s2": s2})
|
| 70 |
+
|
| 71 |
return images
|
| 72 |
|
| 73 |
|
|
|
|
| 212 |
maximum=1000,
|
| 213 |
step=1,
|
| 214 |
value=42)
|
| 215 |
+
|
| 216 |
+
with gr.Group():
|
| 217 |
+
with gr.Row():
|
| 218 |
+
with gr.Accordion("Past generations", open=False):
|
| 219 |
+
gr_user_history.render()
|
| 220 |
+
|
| 221 |
with gr.Row():
|
| 222 |
with gr.Group():
|
| 223 |
# btn = gr.Button("Generate image", scale=0)
|