Wauplin HF staff commited on
Commit
713516b
β€’
1 Parent(s): 27f5f66
Files changed (3) hide show
  1. README.md +4 -1
  2. app.py +1 -1
  3. open_pr.py +8 -1
README.md CHANGED
@@ -4,9 +4,12 @@ emoji: πŸ€–
4
  colorFrom: gray
5
  colorTo: gray
6
  sdk: gradio
7
- sdk_version: 4.7.1
8
  app_file: app.py
9
  pinned: false
 
 
 
10
  space_ci:
11
  trusted_authors:
12
  - clefourrier
 
4
  colorFrom: gray
5
  colorTo: gray
6
  sdk: gradio
7
+ sdk_version: 4.14.0
8
  app_file: app.py
9
  pinned: false
10
+ hf_oauth: true
11
+ hf_oauth_scopes:
12
+ - read
13
  space_ci:
14
  trusted_authors:
15
  - clefourrier
app.py CHANGED
@@ -28,7 +28,7 @@ If you find any issues, please report here: https://huggingface.co/spaces/Waupli
28
 
29
  interface = gr.Interface(
30
  fn=open_pr,
31
- inputs=["text", "text"],
32
  outputs="markdown",
33
  title="Listen to Pull Requests and start ephemeral Spaces on new PRs! πŸš€",
34
  description=DESCRIPTION,
 
28
 
29
  interface = gr.Interface(
30
  fn=open_pr,
31
+ inputs=["text", gr.LoginButton(), gr.LogoutButton()],
32
  outputs="markdown",
33
  title="Listen to Pull Requests and start ephemeral Spaces on new PRs! πŸš€",
34
  description=DESCRIPTION,
open_pr.py CHANGED
@@ -1,4 +1,5 @@
1
  import re
 
2
 
3
  import gradio as gr
4
  from huggingface_hub import CommitOperationAdd, HfApi, RepoUrl, SpaceCard
@@ -41,7 +42,13 @@ You can contact the Space owner to let them know about this PR.
41
  """
42
 
43
 
44
- def open_pr(space_id_or_url: str, token: str) -> str:
 
 
 
 
 
 
45
  api = HfApi(token=token)
46
 
47
  space_id = (
 
1
  import re
2
+ import time
3
 
4
  import gradio as gr
5
  from huggingface_hub import CommitOperationAdd, HfApi, RepoUrl, SpaceCard
 
42
  """
43
 
44
 
45
+ def open_pr(space_id_or_url: str, _1, _2, oauth_token: gr.OAuthToken | None) -> str:
46
+ if oauth_token is None:
47
+ raise gr.Error("You must be logged in to open a PR. Click on 'Sign in with Huggingface' first.")
48
+ token = oauth_token.token
49
+ if oauth_token.expires_at > time.time():
50
+ raise gr.Error("Token expired. Logout and try again.")
51
+
52
  api = HfApi(token=token)
53
 
54
  space_id = (