Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -454,16 +454,10 @@ CRITICAL: Do NOT overthink. Do NOT deliberate over conditions, edge cases, or re
|
|
| 454 |
output_text += new_text2
|
| 455 |
yield output_text, None
|
| 456 |
|
| 457 |
-
# Hard auto-force: if total output exceeds 10K chars
|
| 458 |
-
# the
|
| 459 |
-
# the model
|
| 460 |
-
|
| 461 |
-
text_after_json = output_text[last_json_start:] if last_json_start >= 0 else ''
|
| 462 |
-
has_json_end = (']' in text_after_json or '}' in text_after_json) if text_after_json else False
|
| 463 |
-
should_hard_force = (
|
| 464 |
-
len(output_text) > HARD_FORCE_CHARS
|
| 465 |
-
and not has_json_end
|
| 466 |
-
)
|
| 467 |
|
| 468 |
# Allow user to force again OR hard auto-force kicks in
|
| 469 |
if global_stop_thinking[0] or global_kill_threads[0] or should_hard_force:
|
|
@@ -1654,6 +1648,39 @@ def import_deck_fn(json_file, anki_file):
|
|
| 1654 |
return "<p style='color:#94a3b8;padding:20px;text-align:center;font-family:Outfit,sans-serif;'>β οΈ Please upload a JSON or Anki (.apkg) file above.</p>", None
|
| 1655 |
|
| 1656 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1657 |
def create_demo():
|
| 1658 |
example_pdf = get_example_pdf()
|
| 1659 |
example_audio = get_example_audio()
|
|
@@ -1831,7 +1858,8 @@ def create_demo():
|
|
| 1831 |
with gr.Column(scale=2):
|
| 1832 |
with gr.Tabs() as output_tabs:
|
| 1833 |
with gr.Tab("π Flashcards"):
|
| 1834 |
-
|
|
|
|
| 1835 |
gr.Markdown("**Export current deck:**")
|
| 1836 |
with gr.Row():
|
| 1837 |
export_json_btn = gr.Button("π₯ Export JSON", variant="secondary", size="sm")
|
|
@@ -1842,17 +1870,18 @@ def create_demo():
|
|
| 1842 |
with gr.Tab("β Quiz"):
|
| 1843 |
gr.Markdown("**Test your knowledge** with a randomized 5-question multiple-choice quiz from the current deck.")
|
| 1844 |
start_quiz_btn = gr.Button("π§ͺ Start 5-Question Quiz", variant="primary")
|
| 1845 |
-
|
|
|
|
| 1846 |
|
| 1847 |
stream_box = gr.Textbox(label="Live Model Generation π§ ", lines=10, max_lines=20, interactive=False, autoscroll=True, elem_id="stream_box")
|
| 1848 |
|
| 1849 |
with gr.Accordion("π Extracted Source Content", open=True):
|
| 1850 |
-
extracted_text_box = gr.Textbox(label="Extracted Text", lines=10, max_lines=15, interactive=False)
|
| 1851 |
extracted_images_gallery = gr.Gallery(label="Extracted Images", columns=4, height="auto", object_fit="contain")
|
| 1852 |
extracted_audio_player = gr.Audio(label="Extracted Audio (YouTube / Uploaded)", type="filepath", interactive=False)
|
| 1853 |
|
| 1854 |
last_source_state = gr.State(None)
|
| 1855 |
-
last_korean_words_state = gr.State(
|
| 1856 |
|
| 1857 |
def reset_btn_text():
|
| 1858 |
return gr.update(value="β‘ Stop thinking, Generate now"), gr.update(value="π Stop Generation")
|
|
|
|
| 454 |
output_text += new_text2
|
| 455 |
yield output_text, None
|
| 456 |
|
| 457 |
+
# Hard auto-force: if total output exceeds 10K chars,
|
| 458 |
+
# the model has been rambling too long β force again regardless
|
| 459 |
+
# of JSON state (the model may complete JSON then start over).
|
| 460 |
+
should_hard_force = len(output_text) > HARD_FORCE_CHARS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 461 |
|
| 462 |
# Allow user to force again OR hard auto-force kicks in
|
| 463 |
if global_stop_thinking[0] or global_kill_threads[0] or should_hard_force:
|
|
|
|
| 1648 |
return "<p style='color:#94a3b8;padding:20px;text-align:center;font-family:Outfit,sans-serif;'>β οΈ Please upload a JSON or Anki (.apkg) file above.</p>", None
|
| 1649 |
|
| 1650 |
|
| 1651 |
+
# βββ Bootstrap demo content (shown before any generation) βββ
|
| 1652 |
+
BOOTSTRAP_VOCAB = [
|
| 1653 |
+
{"korean": "μλ
νμΈμ", "translation": "Hello", "transliteration": "an-nyeong-ha-se-yo", "explanation": "The most common formal greeting in Korean, used when meeting someone.", "audio_uri": None},
|
| 1654 |
+
{"korean": "κ°μ¬ν©λλ€", "translation": "Thank you", "transliteration": "gam-sa-ham-ni-da", "explanation": "The standard polite way to express gratitude.", "audio_uri": None},
|
| 1655 |
+
{"korean": "μ¬λ", "translation": "Love", "transliteration": "sa-rang", "explanation": "A fundamental word for love or affection, used in many K-pop songs.", "audio_uri": None},
|
| 1656 |
+
{"korean": "νκ΅", "translation": "School", "transliteration": "hak-gyo", "explanation": "Refers to a school or educational institution. ν means 'study', κ΅ means 'teach'.", "audio_uri": None},
|
| 1657 |
+
{"korean": "μμ", "translation": "Food", "transliteration": "eum-sik", "explanation": "General word for food or cuisine. Korean μμ (food) is world-famous!", "audio_uri": None},
|
| 1658 |
+
{"korean": "μΉκ΅¬", "translation": "Friend", "transliteration": "chin-gu", "explanation": "Means a friend or buddy. In Korean culture, μΉκ΅¬ specifically refers to someone the same age.", "audio_uri": None},
|
| 1659 |
+
{"korean": "λ¬Ό", "translation": "Water", "transliteration": "mul", "explanation": "Essential vocabulary β λ¬Ό μ£ΌμΈμ (mul ju-se-yo) means 'Water, please'.", "audio_uri": None},
|
| 1660 |
+
{"korean": "μκ°", "translation": "Time", "transliteration": "si-gan", "explanation": "Means time or hour. μ (si) = hour, κ° (gan) = interval.", "audio_uri": None},
|
| 1661 |
+
{"korean": "ν볡", "translation": "Happiness", "transliteration": "haeng-bok", "explanation": "Means happiness or bliss. ν볡νλ€ (haeng-bok-ha-da) = to be happy.", "audio_uri": None},
|
| 1662 |
+
{"korean": "μ¬ν", "translation": "Travel", "transliteration": "yeo-haeng", "explanation": "Means travel or trip. μ¬ννλ€ (yeo-haeng-ha-da) = to travel.", "audio_uri": None},
|
| 1663 |
+
]
|
| 1664 |
+
|
| 1665 |
+
DEMO_EXTRACTED_TEXT = """[Demo Content β Common Korean Words]
|
| 1666 |
+
|
| 1667 |
+
μλ
νμΈμ! μ€λμ νκ΅μ΄λ₯Ό λ°°μλ΄
μλ€.
|
| 1668 |
+
(Hello! Let's learn Korean today.)
|
| 1669 |
+
|
| 1670 |
+
νκ΅ μμμ μ λ§ λ§μμ΅λλ€. μΉκ΅¬μ ν¨κ» νκ΅ κ·Όμ² μλΉμμ μ μ¬μ λ¨Ήμμ΅λλ€.
|
| 1671 |
+
(Korean food is really delicious. I had lunch at a restaurant near the school with a friend.)
|
| 1672 |
+
|
| 1673 |
+
μ¬νμ κ°λ©΄ νμ ν볡ν©λλ€. μλ‘μ΄ κ³³μμ μλ‘μ΄ μ¬λλ€μ λ§λλ κ²μ΄ μ’μ΅λλ€.
|
| 1674 |
+
(I'm always happy when I travel. I enjoy meeting new people in new places.)
|
| 1675 |
+
|
| 1676 |
+
λ¬Ό μ£ΌμΈμ! κ°μ¬ν©λλ€.
|
| 1677 |
+
(Water, please! Thank you.)
|
| 1678 |
+
|
| 1679 |
+
μκ°μ΄ 빨리 κ°λλ€. μ¬λνλ μ¬λκ³Ό ν¨κ»νλ©΄ λ 빨리 κ°λλ€.
|
| 1680 |
+
(Time flies. It goes even faster when you're with someone you love.)
|
| 1681 |
+
"""
|
| 1682 |
+
|
| 1683 |
+
|
| 1684 |
def create_demo():
|
| 1685 |
example_pdf = get_example_pdf()
|
| 1686 |
example_audio = get_example_audio()
|
|
|
|
| 1858 |
with gr.Column(scale=2):
|
| 1859 |
with gr.Tabs() as output_tabs:
|
| 1860 |
with gr.Tab("π Flashcards"):
|
| 1861 |
+
bootstrap_html = build_flashcard_html(BOOTSTRAP_VOCAB)
|
| 1862 |
+
output_html = gr.HTML(label="Flashcards will appear here", value=bootstrap_html)
|
| 1863 |
gr.Markdown("**Export current deck:**")
|
| 1864 |
with gr.Row():
|
| 1865 |
export_json_btn = gr.Button("π₯ Export JSON", variant="secondary", size="sm")
|
|
|
|
| 1870 |
with gr.Tab("β Quiz"):
|
| 1871 |
gr.Markdown("**Test your knowledge** with a randomized 5-question multiple-choice quiz from the current deck.")
|
| 1872 |
start_quiz_btn = gr.Button("π§ͺ Start 5-Question Quiz", variant="primary")
|
| 1873 |
+
bootstrap_quiz_html = build_quiz_html(BOOTSTRAP_VOCAB)
|
| 1874 |
+
quiz_output_html = gr.HTML(label="Quiz", value=bootstrap_quiz_html)
|
| 1875 |
|
| 1876 |
stream_box = gr.Textbox(label="Live Model Generation π§ ", lines=10, max_lines=20, interactive=False, autoscroll=True, elem_id="stream_box")
|
| 1877 |
|
| 1878 |
with gr.Accordion("π Extracted Source Content", open=True):
|
| 1879 |
+
extracted_text_box = gr.Textbox(label="Extracted Text", lines=10, max_lines=15, interactive=False, value=DEMO_EXTRACTED_TEXT)
|
| 1880 |
extracted_images_gallery = gr.Gallery(label="Extracted Images", columns=4, height="auto", object_fit="contain")
|
| 1881 |
extracted_audio_player = gr.Audio(label="Extracted Audio (YouTube / Uploaded)", type="filepath", interactive=False)
|
| 1882 |
|
| 1883 |
last_source_state = gr.State(None)
|
| 1884 |
+
last_korean_words_state = gr.State(BOOTSTRAP_VOCAB)
|
| 1885 |
|
| 1886 |
def reset_btn_text():
|
| 1887 |
return gr.update(value="β‘ Stop thinking, Generate now"), gr.update(value="π Stop Generation")
|