vpcom commited on
Commit
f9b040e
·
1 Parent(s): 898bcfb

fix: using oauth approach

Browse files
Files changed (1) hide show
  1. app.py +10 -7
app.py CHANGED
@@ -245,16 +245,19 @@ def vote(data: gr.LikeData):
245
  ]
246
  jsonlfile.write("\n".join(json_data) + "\n")
247
 
248
- def create_greeting(request: gr.Request):
249
  global USERNAME
250
- print(dir(request))
251
- USERNAME = request.username
252
- return gr.Markdown.update(value=f"Thanks for logging in, {request.username}")
253
-
 
 
254
  with gr.Blocks(css=CSS) as demo:
255
 
256
- user_ip = gr.Markdown(value="Not logged in")
257
- demo.load(create_greeting, inputs=None, outputs=user_ip)
 
258
 
259
  with gr.Row():
260
  with gr.Column():
 
245
  ]
246
  jsonlfile.write("\n".join(json_data) + "\n")
247
 
248
+ def hello(profile: gr.OAuthProfile | None) -> str:
249
  global USERNAME
250
+ if profile is None:
251
+ USERNAME = "guest"
252
+ return "I don't know you."
253
+ USERNAME = profile.name
254
+ return f"Hello {profile.name}"
255
+
256
  with gr.Blocks(css=CSS) as demo:
257
 
258
+ gr.LoginButton()
259
+ gr.LogoutButton()
260
+ gr.Markdown().attach_load_event(hello, None)
261
 
262
  with gr.Row():
263
  with gr.Column():