Spaces:
Runtime error
Runtime error
Raymond Weitekamp
commited on
Commit
·
a5081e4
1
Parent(s):
d0c43d9
Add proper OAuth login button and profile handling
Browse files
app.py
CHANGED
@@ -92,12 +92,13 @@ def create_gradio_interface():
|
|
92 |
gr.Markdown("## Crowdsourcing Handwriting OCR Dataset")
|
93 |
|
94 |
with gr.Row():
|
|
|
95 |
user_info = gr.Markdown("")
|
96 |
|
97 |
-
def update_user_info(
|
98 |
-
if
|
99 |
-
return f"Logged in as: {
|
100 |
-
return "Please log in with your Hugging Face account to contribute to the dataset."
|
101 |
|
102 |
with gr.Column(visible=False) as main_interface:
|
103 |
gr.Markdown("You will be shown between 1 and 5 consecutive sentences. Please handwrite them on paper and upload an image of your handwriting. If you wish to skip the current text, click 'Skip'.")
|
@@ -109,30 +110,31 @@ def create_gradio_interface():
|
|
109 |
submit_btn = gr.Button("Submit")
|
110 |
skip_btn = gr.Button("Skip")
|
111 |
|
112 |
-
def check_login(
|
113 |
-
if
|
114 |
raise gr.Error("Please log in to use this application")
|
115 |
-
return
|
116 |
|
117 |
-
def protected_submit(image, text_block,
|
118 |
-
username = check_login(
|
119 |
return collector.submit_image(image, text_block, username)
|
120 |
|
121 |
-
def protected_skip(text_block,
|
122 |
-
username = check_login(
|
123 |
return collector.skip_text(text_block, username)
|
124 |
|
125 |
-
demo.load(update_user_info, outputs=[user_info
|
|
|
126 |
|
127 |
submit_btn.click(
|
128 |
fn=protected_submit,
|
129 |
-
inputs=[image_input, text_box],
|
130 |
outputs=text_box
|
131 |
)
|
132 |
|
133 |
skip_btn.click(
|
134 |
fn=protected_skip,
|
135 |
-
inputs=[text_box],
|
136 |
outputs=text_box
|
137 |
)
|
138 |
|
@@ -140,4 +142,4 @@ def create_gradio_interface():
|
|
140 |
|
141 |
if __name__ == "__main__":
|
142 |
demo = create_gradio_interface()
|
143 |
-
demo.launch(
|
|
|
92 |
gr.Markdown("## Crowdsourcing Handwriting OCR Dataset")
|
93 |
|
94 |
with gr.Row():
|
95 |
+
gr.LoginButton()
|
96 |
user_info = gr.Markdown("")
|
97 |
|
98 |
+
def update_user_info(profile: gr.OAuthProfile | None) -> str:
|
99 |
+
if profile:
|
100 |
+
return f"Logged in as: {profile.name}"
|
101 |
+
return "Please log in with your Hugging Face account to contribute to the dataset."
|
102 |
|
103 |
with gr.Column(visible=False) as main_interface:
|
104 |
gr.Markdown("You will be shown between 1 and 5 consecutive sentences. Please handwrite them on paper and upload an image of your handwriting. If you wish to skip the current text, click 'Skip'.")
|
|
|
110 |
submit_btn = gr.Button("Submit")
|
111 |
skip_btn = gr.Button("Skip")
|
112 |
|
113 |
+
def check_login(profile: gr.OAuthProfile | None) -> str:
|
114 |
+
if profile is None:
|
115 |
raise gr.Error("Please log in to use this application")
|
116 |
+
return profile.name
|
117 |
|
118 |
+
def protected_submit(image, text_block, profile: gr.OAuthProfile | None):
|
119 |
+
username = check_login(profile)
|
120 |
return collector.submit_image(image, text_block, username)
|
121 |
|
122 |
+
def protected_skip(text_block, profile: gr.OAuthProfile | None):
|
123 |
+
username = check_login(profile)
|
124 |
return collector.skip_text(text_block, username)
|
125 |
|
126 |
+
demo.load(update_user_info, inputs=gr.OAuthProfile(), outputs=[user_info])
|
127 |
+
demo.load(lambda p: gr.update(visible=p is not None), inputs=gr.OAuthProfile(), outputs=[main_interface])
|
128 |
|
129 |
submit_btn.click(
|
130 |
fn=protected_submit,
|
131 |
+
inputs=[image_input, text_box, gr.OAuthProfile()],
|
132 |
outputs=text_box
|
133 |
)
|
134 |
|
135 |
skip_btn.click(
|
136 |
fn=protected_skip,
|
137 |
+
inputs=[text_box, gr.OAuthProfile()],
|
138 |
outputs=text_box
|
139 |
)
|
140 |
|
|
|
142 |
|
143 |
if __name__ == "__main__":
|
144 |
demo = create_gradio_interface()
|
145 |
+
demo.launch()
|