Spaces:
Runtime error
Runtime error
Update
Browse files
app.py
CHANGED
|
@@ -21,6 +21,43 @@ USE_PUBLIC_REPO = os.getenv('USE_PUBLIC_REPO') == '1'
|
|
| 21 |
LOCAL_SAVE_DIR = pathlib.Path(os.getenv('LOCAL_SAVE_DIR', 'results'))
|
| 22 |
LOCAL_SAVE_DIR.mkdir(parents=True, exist_ok=True)
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
scheduler = ZipScheduler(repo_id=UPLOAD_REPO_ID,
|
| 25 |
repo_type='dataset',
|
| 26 |
every=UPLOAD_FREQUENCY,
|
|
@@ -100,43 +137,7 @@ with gr.Blocks(css='style.css') as demo:
|
|
| 100 |
save_preference_button = gr.Button('Save preference', interactive=False)
|
| 101 |
|
| 102 |
with gr.Accordion(label='About this Space', open=False):
|
| 103 |
-
gr.Markdown(
|
| 104 |
-
This Space is a sample Space that collects user preferences for the results generated by a diffusion model.
|
| 105 |
-
This demo calls the [stable diffusion Space](https://huggingface.co/spaces/stabilityai/stable-diffusion) with the [`gradio_client`](https://pypi.org/project/gradio-client/) library.
|
| 106 |
-
|
| 107 |
-
The user preference data is periodically zipped and uploaded to [this dataset repo](https://huggingface.co/datasets/hysts-samples/sample-user-preferences).
|
| 108 |
-
The directory structure of the zipped data is as follows:
|
| 109 |
-
```
|
| 110 |
-
results
|
| 111 |
-
├── 11e11b01-3388-48b3-a2ab-1b58d156e466
|
| 112 |
-
│ ├── 000.jpg
|
| 113 |
-
│ ├── 001.jpg
|
| 114 |
-
│ ├── 002.jpg
|
| 115 |
-
│ ├── 003.jpg
|
| 116 |
-
│ └── preferences.json
|
| 117 |
-
├── 1470ec1d-67a1-47ae-ab9c-4e0e0594dadf
|
| 118 |
-
│ ├── 000.jpg
|
| 119 |
-
│ ├── 001.jpg
|
| 120 |
-
│ ├── 002.jpg
|
| 121 |
-
│ ├── 003.jpg
|
| 122 |
-
│ └── preferences.json
|
| 123 |
-
...
|
| 124 |
-
```
|
| 125 |
-
Also, each `preferences.json` looks like this:
|
| 126 |
-
```
|
| 127 |
-
{
|
| 128 |
-
"prompt": "an astronaut riding a horse",
|
| 129 |
-
"negative_prompt": "",
|
| 130 |
-
"guidance_scale": 9,
|
| 131 |
-
"selected_index": 2,
|
| 132 |
-
"timestamp": "2023-06-15T07:57:00.097883"
|
| 133 |
-
}
|
| 134 |
-
```
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
The periodic upload is done using [`huggingface_hub.CommitScheduler`](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/hf_api#huggingface_hub.CommitScheduler).
|
| 138 |
-
See [this Space](https://huggingface.co/spaces/Wauplin/space_to_dataset_saver) for more general usage.
|
| 139 |
-
''')
|
| 140 |
|
| 141 |
prompt.submit(
|
| 142 |
fn=generate,
|
|
|
|
| 21 |
LOCAL_SAVE_DIR = pathlib.Path(os.getenv('LOCAL_SAVE_DIR', 'results'))
|
| 22 |
LOCAL_SAVE_DIR.mkdir(parents=True, exist_ok=True)
|
| 23 |
|
| 24 |
+
ABOUT_THIS_SPACE = '''
|
| 25 |
+
This Space is a sample Space that collects user preferences for the results generated by a diffusion model.
|
| 26 |
+
This demo calls the [stable diffusion Space](https://huggingface.co/spaces/stabilityai/stable-diffusion) with the [`gradio_client`](https://pypi.org/project/gradio-client/) library.
|
| 27 |
+
|
| 28 |
+
The user preference data is periodically zipped and uploaded to [this dataset repo](https://huggingface.co/datasets/hysts-samples/sample-user-preferences).
|
| 29 |
+
The directory structure of the zipped data is as follows:
|
| 30 |
+
```
|
| 31 |
+
results
|
| 32 |
+
├── 11e11b01-3388-48b3-a2ab-1b58d156e466
|
| 33 |
+
│ ├── 000.jpg
|
| 34 |
+
│ ├── 001.jpg
|
| 35 |
+
│ ├── 002.jpg
|
| 36 |
+
│ ├── 003.jpg
|
| 37 |
+
│ └── preferences.json
|
| 38 |
+
├── 1470ec1d-67a1-47ae-ab9c-4e0e0594dadf
|
| 39 |
+
│ ├── 000.jpg
|
| 40 |
+
│ ├── 001.jpg
|
| 41 |
+
│ ├── 002.jpg
|
| 42 |
+
│ ├── 003.jpg
|
| 43 |
+
│ └── preferences.json
|
| 44 |
+
...
|
| 45 |
+
```
|
| 46 |
+
Also, each `preferences.json` looks like this:
|
| 47 |
+
```
|
| 48 |
+
{
|
| 49 |
+
"prompt": "an astronaut riding a horse",
|
| 50 |
+
"negative_prompt": "",
|
| 51 |
+
"guidance_scale": 9,
|
| 52 |
+
"selected_index": 2,
|
| 53 |
+
"timestamp": "2023-06-15T07:57:00.097883"
|
| 54 |
+
}
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
The periodic upload is done using [`huggingface_hub.CommitScheduler`](https://huggingface.co/docs/huggingface_hub/main/en/package_reference/hf_api#huggingface_hub.CommitScheduler).
|
| 58 |
+
See [this Space](https://huggingface.co/spaces/Wauplin/space_to_dataset_saver) for more general usage.
|
| 59 |
+
'''
|
| 60 |
+
|
| 61 |
scheduler = ZipScheduler(repo_id=UPLOAD_REPO_ID,
|
| 62 |
repo_type='dataset',
|
| 63 |
every=UPLOAD_FREQUENCY,
|
|
|
|
| 137 |
save_preference_button = gr.Button('Save preference', interactive=False)
|
| 138 |
|
| 139 |
with gr.Accordion(label='About this Space', open=False):
|
| 140 |
+
gr.Markdown(ABOUT_THIS_SPACE)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
|
| 142 |
prompt.submit(
|
| 143 |
fn=generate,
|