RoAr777 commited on
Commit
dd4cc8c
·
verified ·
1 Parent(s): 4f77375

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -32
app.py CHANGED
@@ -1,36 +1,41 @@
1
  import gradio as gr
 
 
 
 
 
 
 
 
 
2
 
3
- with gr.Blocks() as demo:
4
- # Title of the app
5
- gr.Markdown("# Welcome to the Dynamic App!")
6
 
7
-
8
- with gr.Row(visible=True) as form_section:
9
- gr.LoginButton(scale=1)
10
-
11
-
12
- # Output message after successful submission
13
-
14
-
15
- # Main content shown after form submission
16
- with gr.Column(visible=gr.OAuthProfile is not None) as main_content:
17
- form_section.visible=False
18
- gr.Markdown("Thank you for entering your details. Here’s where the app’s main content goes!")
19
-
20
- # Personalized welcome message
21
- personal_message = gr.Textbox(
22
- label="",
23
- interactive=False,
24
- value="You have access to all the interactive features below.",
25
- visible=True
26
- )
 
 
 
 
 
 
 
27
 
28
- # Feature selection dropdown
29
- feature = gr.Dropdown(
30
- ["Data Visualization", "Model Prediction", "Statistics", "Text Analysis"],
31
- label="Choose a feature to explore:"
32
- )
33
-
34
-
35
- # Launch the app
36
- demo.launch()
 
1
  import gradio as gr
2
+ from huggingface_hub import list_models
3
+
4
+
5
+ def hello(profile: gr.OAuthProfile | None) -> str:
6
+ # ^ expect a gr.OAuthProfile object as input to get the user's profile
7
+ # if the user is not logged in, profile will be None
8
+ if profile is None:
9
+ return "I don't know you."
10
+ return f"Hello {profile.name}"
11
 
 
 
 
12
 
13
+ def list_private_models(profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
14
+ # ^ expect a gr.OAuthToken object as input to get the user's token
15
+ # if the user is not logged in, oauth_token will be None
16
+ if oauth_token is None:
17
+ return "Please log in to list private models."
18
+ models = [
19
+ f"{model.id} ({'private' if model.private else 'public'})"
20
+ for model in list_models(author=profile.username, token=oauth_token.token)
21
+ ]
22
+ return "Models:\n\n" + "\n - ".join(models) + "."
23
+
24
+
25
+ with gr.Blocks() as demo:
26
+ gr.Markdown(
27
+ "# Gradio OAuth Space"
28
+ "\n\nThis Space is a demo for the **Sign in with Hugging Face** feature. "
29
+ "Duplicate this Space to get started."
30
+ "\n\nFor more details, check out:"
31
+ "\n- https://www.gradio.app/guides/sharing-your-app#o-auth-login-via-hugging-face"
32
+ "\n- https://huggingface.co/docs/hub/spaces-oauth"
33
+ )
34
+ gr.LoginButton()
35
+ # ^ add a login button to the Space
36
+ m1 = gr.Markdown()
37
+ m2 = gr.Markdown()
38
+ demo.load(hello, inputs=None, outputs=m1)
39
+ demo.load(list_private_models, inputs=None, outputs=m2)
40
 
41
+ demo.launch()