maryna7679 commited on
Commit
c3f878d
·
1 Parent(s): b3bc292

Huggingface auth login

Browse files
Files changed (1) hide show
  1. app.py +31 -22
app.py CHANGED
@@ -10,7 +10,7 @@ user = ""
10
  def get_username(profile: gr.OAuthProfile):
11
  global user
12
  user = profile.username
13
- return profile.username
14
 
15
 
16
  def save(df, video_id):
@@ -36,28 +36,37 @@ def get_next_components():
36
  (start_video, start_captions, start_video_id) = get_next_components()
37
 
38
  with gr.Blocks(css=css) as main_page:
39
- gr.Markdown("## Caption Editor")
 
40
  gr.LoginButton()
41
- m1 = gr.Markdown()
 
42
  current_video_id = gr.Textbox(value=start_video_id, visible=False, interactive=False)
43
- with gr.Row():
44
- with gr.Column():
45
- caption_editor = gr.DataFrame(interactive=True,
46
- value=start_captions,
47
- datatype=["number", "str", "number"],
48
- row_count=(start_captions.shape[0], "fixed"),
49
- col_count=(3, "fixed"), column_widths=["20%", "60%", "20%"])
50
- save_button = gr.Button(value="Save")
51
- save_result = gr.Markdown()
52
- with gr.Column():
53
- video_embed = gr.HTML(value=start_video)
54
- next_video_button = gr.Button("Next")
55
-
56
- next_video_button.click(fn=get_next_components,
57
- outputs=[video_embed, caption_editor, current_video_id])
58
- save_button.click(fn=save,
59
- inputs=[caption_editor, current_video_id],
60
- outputs=save_result)
61
- main_page.load(get_username, outputs=m1)
 
 
 
 
 
 
 
62
 
63
  main_page.launch(share=True, ssr_mode=False)
 
10
  def get_username(profile: gr.OAuthProfile):
11
  global user
12
  user = profile.username
13
+ return profile
14
 
15
 
16
  def save(df, video_id):
 
36
  (start_video, start_captions, start_video_id) = get_next_components()
37
 
38
  with gr.Blocks(css=css) as main_page:
39
+ gr.Markdown("# Caption Editor")
40
+
41
  gr.LoginButton()
42
+
43
+ current_user = gr.Textbox(visible=False, interactive=False)
44
  current_video_id = gr.Textbox(value=start_video_id, visible=False, interactive=False)
45
+
46
+ main_page.load(get_username, outputs=current_user)
47
+
48
+ @gr.render(inputs=current_user)
49
+ def render_page(logged_in_user):
50
+ if logged_in_user is None:
51
+ gr.Markdown("## Please log in via Hugging Face")
52
+ else:
53
+ with gr.Row():
54
+ with gr.Column():
55
+ caption_editor = gr.DataFrame(interactive=True,
56
+ value=start_captions,
57
+ datatype=["number", "str", "number"],
58
+ row_count=(start_captions.shape[0], "fixed"),
59
+ col_count=(3, "fixed"), column_widths=["20%", "60%", "20%"])
60
+ save_button = gr.Button(value="Save")
61
+ save_result = gr.Markdown()
62
+ with gr.Column():
63
+ video_embed = gr.HTML(value=start_video)
64
+ next_video_button = gr.Button("Next")
65
+
66
+ next_video_button.click(fn=get_next_components,
67
+ outputs=[video_embed, caption_editor, current_video_id])
68
+ save_button.click(fn=save,
69
+ inputs=[caption_editor, current_video_id],
70
+ outputs=save_result)
71
 
72
  main_page.launch(share=True, ssr_mode=False)