Skip to content

Commit

Permalink
demo
Browse files Browse the repository at this point in the history
  • Loading branch information
abidlabs committed Nov 15, 2024
1 parent af7f2f5 commit ecfbe4b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
3 changes: 2 additions & 1 deletion demo/load_model_with_token/run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import gradio as gr

demo = gr.load("google/vit-base-patch16-224", src="models", accept_token=True)
# This demo requires a Hugging Face PRO token.
demo = gr.load("meta-llama/Meta-Llama-3-8B-Instruct", src="models", accept_token=True)

if __name__ == "__main__":
demo.launch()
30 changes: 22 additions & 8 deletions gradio/external.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,31 @@ def load(
import gradio as gr

with gr.Blocks(fill_height=True) as demo:
textbox = gr.Textbox(
type="password",
label="Enter your token and press enter",
)
remember_token = gr.Checkbox(label="Remember me on this device", value=False)
browser_state = gr.BrowserState()
with gr.Accordion("Enter your token and press enter") as accordion:
textbox = gr.Textbox(
type="password",
show_label=False,
container=False,
)
remember_token = gr.Checkbox(
label="Remember me on this device", value=False, container=False
)
browser_state = gr.BrowserState()

@gr.on([textbox.submit, remember_token.change], inputs=[textbox, remember_token], outputs=[browser_state, remember_token])
@gr.on([textbox.submit], outputs=accordion)
def hide_accordion():
return gr.Accordion("Token settings", open=False)

@gr.on(
[textbox.submit, remember_token.change],
inputs=[textbox, remember_token],
outputs=[browser_state, remember_token],
)
def save_token(token_value, remember_token_value):
if remember_token_value and token_value:
return token_value, gr.Checkbox(label="Remember me on this device (saved!)", value=True)
return token_value, gr.Checkbox(
label="Remember me on this device (saved!)", value=True
)
else:
return "", gr.Checkbox(label="Remember me on this device")

Expand Down

0 comments on commit ecfbe4b

Please sign in to comment.