Show warning when HF_TOKEN is not specified
Browse files
app.py
CHANGED
@@ -21,6 +21,7 @@ SHARED_UI_WARNING = f'''# Attention - This Space doesn't work in this shared UI.
|
|
21 |
|
22 |
<center><a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></center>
|
23 |
'''
|
|
|
24 |
if os.getenv('SYSTEM') == 'spaces' and SPACE_ID != ORIGINAL_SPACE_ID:
|
25 |
SETTINGS = f'<a href="https://huggingface.co/spaces/{SPACE_ID}/settings">Settings</a>'
|
26 |
else:
|
@@ -32,6 +33,13 @@ You can assign a GPU in the {SETTINGS} tab if you are running this on HF Spaces.
|
|
32 |
</center>
|
33 |
'''
|
34 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
35 |
HF_TOKEN = os.getenv('HF_TOKEN')
|
36 |
|
37 |
|
@@ -50,6 +58,8 @@ with gr.Blocks(css='style.css') as demo:
|
|
50 |
show_warning(SHARED_UI_WARNING)
|
51 |
if not torch.cuda.is_available():
|
52 |
show_warning(CUDA_NOT_AVAILABLE_WARNING)
|
|
|
|
|
53 |
|
54 |
gr.Markdown(TITLE)
|
55 |
with gr.Tabs():
|
|
|
21 |
|
22 |
<center><a class="duplicate-button" style="display:inline-block" target="_blank" href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true"><img src="https://img.shields.io/badge/-Duplicate%20Space-blue?labelColor=white&style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAP5JREFUOE+lk7FqAkEURY+ltunEgFXS2sZGIbXfEPdLlnxJyDdYB62sbbUKpLbVNhyYFzbrrA74YJlh9r079973psed0cvUD4A+4HoCjsA85X0Dfn/RBLBgBDxnQPfAEJgBY+A9gALA4tcbamSzS4xq4FOQAJgCDwV2CPKV8tZAJcAjMMkUe1vX+U+SMhfAJEHasQIWmXNN3abzDwHUrgcRGmYcgKe0bxrblHEB4E/pndMazNpSZGcsZdBlYJcEL9Afo75molJyM2FxmPgmgPqlWNLGfwZGG6UiyEvLzHYDmoPkDDiNm9JR9uboiONcBXrpY1qmgs21x1QwyZcpvxt9NS09PlsPAAAAAElFTkSuQmCC&logoWidth=14" alt="Duplicate Space"></a></center>
|
23 |
'''
|
24 |
+
|
25 |
if os.getenv('SYSTEM') == 'spaces' and SPACE_ID != ORIGINAL_SPACE_ID:
|
26 |
SETTINGS = f'<a href="https://huggingface.co/spaces/{SPACE_ID}/settings">Settings</a>'
|
27 |
else:
|
|
|
33 |
</center>
|
34 |
'''
|
35 |
|
36 |
+
HF_TOKEN_NOT_SPECIFIED_WARNING = f'''# Attention - The environment variable `HF_TOKEN` is not specified. Please specify your Hugging Face token with write permission as the value of it.
|
37 |
+
<center>
|
38 |
+
You can check and create your Hugging Face tokens <a href="https://huggingface.co/settings/tokens" target="_blank">here</a>.
|
39 |
+
You can specify environment variables in the "Repository secrets" section of the {SETTINGS} tab.
|
40 |
+
</center>
|
41 |
+
'''
|
42 |
+
|
43 |
HF_TOKEN = os.getenv('HF_TOKEN')
|
44 |
|
45 |
|
|
|
58 |
show_warning(SHARED_UI_WARNING)
|
59 |
if not torch.cuda.is_available():
|
60 |
show_warning(CUDA_NOT_AVAILABLE_WARNING)
|
61 |
+
if not HF_TOKEN:
|
62 |
+
show_warning(HF_TOKEN_NOT_SPECIFIED_WARNING)
|
63 |
|
64 |
gr.Markdown(TITLE)
|
65 |
with gr.Tabs():
|