Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -12,6 +12,8 @@ DATASET_REPO = "gursul/german_exercise_dataset"
|
|
| 12 |
ENGLISH_WORDS_FILE = "en_de.json"
|
| 13 |
GERMAN_WORDS_FILE = "de_en.json"
|
| 14 |
|
|
|
|
|
|
|
| 15 |
# Authenticate once at startup
|
| 16 |
if "HF_TOKEN" in os.environ:
|
| 17 |
login(token=os.environ["HF_TOKEN"])
|
|
@@ -338,8 +340,49 @@ MEME_PATH = hf_hub_download(
|
|
| 338 |
repo_type="dataset"
|
| 339 |
)
|
| 340 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
# Gradio UI
|
| 342 |
with gr.Blocks() as demo:
|
|
|
|
| 343 |
with gr.Tab("Word Translation"):
|
| 344 |
with gr.Row():
|
| 345 |
# ========= EN → DE =========
|
|
@@ -377,13 +420,19 @@ with gr.Blocks() as demo:
|
|
| 377 |
de_submit_btn = gr.Button("Check Answer (DE→EN)")
|
| 378 |
|
| 379 |
with gr.Tab("Words Dataset"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
with gr.Row():
|
| 381 |
with gr.Column():
|
| 382 |
-
english_in = gr.Textbox(label="English Word")
|
| 383 |
-
type_in = gr.Dropdown(label="Word Type", choices=["noun", "verb", "other"], value="noun")
|
| 384 |
-
article_in = gr.Textbox(label="Artikel (der/die/das) — only for nouns")
|
| 385 |
-
german_in = gr.Textbox(label="German Translation")
|
| 386 |
-
add_btn = gr.Button("Add Word")
|
| 387 |
add_result = gr.Markdown("Let's add some words!!!")
|
| 388 |
with gr.Column():
|
| 389 |
meme_img = gr.Image(
|
|
@@ -396,9 +445,9 @@ with gr.Blocks() as demo:
|
|
| 396 |
height=159, #320x215
|
| 397 |
width=320*(159/215)-1
|
| 398 |
)
|
| 399 |
-
delete_word_in = gr.Textbox(label="Word to Delete")
|
| 400 |
-
delete_lang_in = gr.Dropdown(label="Language", choices=["English", "Deutsch"], value="English")
|
| 401 |
-
delete_btn = gr.Button("Delete Word")
|
| 402 |
delete_result = gr.Markdown("So you're deleting me...")
|
| 403 |
|
| 404 |
with gr.Row(equal_height=True):
|
|
@@ -483,4 +532,16 @@ with gr.Blocks() as demo:
|
|
| 483 |
outputs=[search_box, word_table_en_de, word_table_de_en]
|
| 484 |
)
|
| 485 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 486 |
demo.launch()
|
|
|
|
| 12 |
ENGLISH_WORDS_FILE = "en_de.json"
|
| 13 |
GERMAN_WORDS_FILE = "de_en.json"
|
| 14 |
|
| 15 |
+
PASSWORD = "setriavret"
|
| 16 |
+
|
| 17 |
# Authenticate once at startup
|
| 18 |
if "HF_TOKEN" in os.environ:
|
| 19 |
login(token=os.environ["HF_TOKEN"])
|
|
|
|
| 340 |
repo_type="dataset"
|
| 341 |
)
|
| 342 |
|
| 343 |
+
# Password unlock
|
| 344 |
+
def unlock_section(pwd, current_auth):
|
| 345 |
+
if current_auth:
|
| 346 |
+
return (
|
| 347 |
+
current_auth,
|
| 348 |
+
"",
|
| 349 |
+
gr.update(interactive=True),
|
| 350 |
+
gr.update(interactive=True),
|
| 351 |
+
gr.update(interactive=True),
|
| 352 |
+
gr.update(interactive=True),
|
| 353 |
+
gr.update(interactive=True),
|
| 354 |
+
gr.update(interactive=True),
|
| 355 |
+
gr.update(interactive=True),
|
| 356 |
+
gr.update(interactive=True),
|
| 357 |
+
"✅ Access Already Granted!"
|
| 358 |
+
)
|
| 359 |
+
if pwd == PASSWORD:
|
| 360 |
+
return (
|
| 361 |
+
True,
|
| 362 |
+
"",
|
| 363 |
+
gr.update(interactive=True),
|
| 364 |
+
gr.update(interactive=True),
|
| 365 |
+
gr.update(interactive=True),
|
| 366 |
+
gr.update(interactive=True),
|
| 367 |
+
gr.update(interactive=True),
|
| 368 |
+
gr.update(interactive=True),
|
| 369 |
+
gr.update(interactive=True),
|
| 370 |
+
gr.update(interactive=True),
|
| 371 |
+
"✅ Access Granted! You can now add/delete words."
|
| 372 |
+
)
|
| 373 |
+
else:
|
| 374 |
+
return (
|
| 375 |
+
False,
|
| 376 |
+
pwd,
|
| 377 |
+
gr.update(), gr.update(), gr.update(),
|
| 378 |
+
gr.update(), gr.update(),
|
| 379 |
+
gr.update(), gr.update(), gr.update(),
|
| 380 |
+
"❌ Wrong Password! Try again."
|
| 381 |
+
)
|
| 382 |
+
|
| 383 |
# Gradio UI
|
| 384 |
with gr.Blocks() as demo:
|
| 385 |
+
authenticated = gr.State(False) # Session-based state
|
| 386 |
with gr.Tab("Word Translation"):
|
| 387 |
with gr.Row():
|
| 388 |
# ========= EN → DE =========
|
|
|
|
| 420 |
de_submit_btn = gr.Button("Check Answer (DE→EN)")
|
| 421 |
|
| 422 |
with gr.Tab("Words Dataset"):
|
| 423 |
+
gr.Markdown("### Manage Words (Password Required)")
|
| 424 |
+
with gr.Row():
|
| 425 |
+
login_password = gr.Textbox(label="Enter Password", type="password", scale=5)
|
| 426 |
+
login_btn = gr.Button("Unlock Add/Delete Section", scale=1)
|
| 427 |
+
login_status = gr.Markdown("Are you the one who holds the key?")
|
| 428 |
+
|
| 429 |
with gr.Row():
|
| 430 |
with gr.Column():
|
| 431 |
+
english_in = gr.Textbox(label="English Word", interactive=False)
|
| 432 |
+
type_in = gr.Dropdown(label="Word Type", choices=["noun", "verb", "other"], value="noun", interactive=False)
|
| 433 |
+
article_in = gr.Textbox(label="Artikel (der/die/das) — only for nouns", interactive=False)
|
| 434 |
+
german_in = gr.Textbox(label="German Translation", interactive=False)
|
| 435 |
+
add_btn = gr.Button("Add Word", interactive=False)
|
| 436 |
add_result = gr.Markdown("Let's add some words!!!")
|
| 437 |
with gr.Column():
|
| 438 |
meme_img = gr.Image(
|
|
|
|
| 445 |
height=159, #320x215
|
| 446 |
width=320*(159/215)-1
|
| 447 |
)
|
| 448 |
+
delete_word_in = gr.Textbox(label="Word to Delete", interactive=False)
|
| 449 |
+
delete_lang_in = gr.Dropdown(label="Language", choices=["English", "Deutsch"], value="English", interactive=False)
|
| 450 |
+
delete_btn = gr.Button("Delete Word", interactive=False)
|
| 451 |
delete_result = gr.Markdown("So you're deleting me...")
|
| 452 |
|
| 453 |
with gr.Row(equal_height=True):
|
|
|
|
| 532 |
outputs=[search_box, word_table_en_de, word_table_de_en]
|
| 533 |
)
|
| 534 |
|
| 535 |
+
login_btn.click(
|
| 536 |
+
unlock_section,
|
| 537 |
+
inputs=[login_password, authenticated],
|
| 538 |
+
outputs=[
|
| 539 |
+
authenticated,
|
| 540 |
+
login_password,
|
| 541 |
+
english_in, type_in, article_in, german_in, add_btn,
|
| 542 |
+
delete_word_in, delete_lang_in, delete_btn,
|
| 543 |
+
login_status
|
| 544 |
+
]
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
demo.launch()
|