1. Enable OAuth to your Space

Simply edit your Space metadata in your README.md file:

# README.md
hf_oauth: true

2. Update your requirements.txt

# requirements.txt
git+https://huggingface.co/spaces/Surn/gradio-user-history
filetype @ git+https://github.com/h2non/filetype.py.git
gradio[oauth]
mutagen
tqdm
torch==2.6.0 --extra-index-url https://download.pytorch.org/whl/cu124
torchaudio>=2.0.0,<2.6.2 --extra-index-url https://download.pytorch.org/whl/cu124

3. Integrate into your Gradio app

# app.py
import gradio as gr
import gradio_user_history as gr_user_history
(...)

# => Inject gr.OAuthProfile
def generate(prompt: str, profile: gr.OAuthProfile | None):
    image = ...

    # => Save generated image(s)
    gr_user_history.save_image(label=prompt, image=image, profile=profile)

    # => Save generated image, video, audio, document, metadata
    gr_user_history.save_file(profile=profile,image=image, video=video, audio=audio, document=document,label=string, metadata=metadata)


# => Render user history
with gr.Blocks() as demo:
    (...)

    with gr.Accordion("Past generations", open=False):
        # => OPTIONALLY display images or videos in the history gallery with display_type: "image_path" or "video_path" or "audio_path" or "document_path"
        gr_user_history.setup(display_type="image_path")
        gr_user_history.render()

4. (optional) Add Persistent Storage in your Space settings. Persistent Storage is suggested but not mandatory. If not enabled, the history is lost each time the Space restarts.

And you're done!

Useful links

Preview