Update app.py
Browse files
app.py
CHANGED
|
@@ -21,7 +21,8 @@ def load_data():
|
|
| 21 |
try:
|
| 22 |
content = raw_data.decode(encoding)
|
| 23 |
content = html.unescape(content)
|
| 24 |
-
|
|
|
|
| 25 |
if len(df.columns) >= 3:
|
| 26 |
df = df.rename(columns={0: "Kirm", 1: "Tr", 2: "De", 3: "En"})
|
| 27 |
df = df.fillna("")
|
|
@@ -45,42 +46,45 @@ def markiere_rot(text, suchwort):
|
|
| 45 |
pattern = re.compile(re.escape(str(suchwort)), re.IGNORECASE)
|
| 46 |
return pattern.sub(lambda m: f"<span style='color:#e53935; font-weight:bold;'>{m.group(0)}</span>", text_str)
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
def
|
| 50 |
if DF_GLOBAL is None or DF_GLOBAL.empty:
|
| 51 |
return "⚠️ Veriler yüklenemedi.", ""
|
|
|
|
| 52 |
total = len(DF_GLOBAL)
|
| 53 |
seed = int(datetime.now().strftime("%Y%m%d"))
|
| 54 |
-
wotd_row = DF_GLOBAL.sample(n=1, random_state=seed).iloc[0]
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
langs = []
|
| 59 |
if str(wotd_row.get('Tr', '')).strip(): langs.append(f"🇹🇷 {wotd_row['Tr']}")
|
| 60 |
if str(wotd_row.get('De', '')).strip(): langs.append(f"🇩🇪 {wotd_row['De']}")
|
| 61 |
-
if 'En' in wotd_row and str(wotd_row.get('En', '')).strip(): langs.append(f"🇬🇧 {wotd_row['En']}")
|
| 62 |
-
lang_html = "<br>".join(langs)
|
| 63 |
|
| 64 |
wotd_html = f"""
|
| 65 |
<div style='background-color: #f1f4ff; color: #1a237e; padding: 20px; border-radius: 12px; border-left: 8px solid #3f51b5; margin: 15px 0; border: 1px solid #d1d9ff;'>
|
| 66 |
<small style='color: #3f51b5; text-transform: uppercase; font-weight: bold;'>ROCA QESEY (Günün Kelimesi):</small><br>
|
| 67 |
<div style='margin-top: 10px;'>
|
| 68 |
<b style='font-size: 2em;'>{wotd_row['Kirm']}</b><br>
|
| 69 |
-
<div style='font-size: 1.1em; margin-top: 5px; color: #303f9f;'>{
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
"""
|
| 73 |
-
return
|
| 74 |
|
| 75 |
js_speak = "function speak(text) { window.speechSynthesis.cancel(); const msg = new SpeechSynthesisUtterance(text); msg.lang = 'tr-TR'; msg.rate = 0.5; window.speechSynthesis.speak(msg); }"
|
| 76 |
|
|
|
|
| 77 |
def suche(wort):
|
| 78 |
wort = str(wort).strip()
|
| 79 |
if len(wort) < 2: return "<p style='text-align:center; color:#777;'>✍️ Bınusnê...</p>"
|
| 80 |
if DF_GLOBAL is None: return "Hata."
|
|
|
|
| 81 |
mask = DF_GLOBAL.astype(str).apply(lambda x: x.str.contains(wort, case=False, na=False)).any(axis=1)
|
| 82 |
ergebnis = DF_GLOBAL[mask].head(50)
|
|
|
|
| 83 |
if ergebnis.empty: return "<h3 style='text-align:center;'>❌ Çino.</h3>"
|
|
|
|
| 84 |
html_output = ""
|
| 85 |
for _, row in ergebnis.iterrows():
|
| 86 |
clean_text = str(row['Kirm']).replace("'", "\\'")
|
|
@@ -88,8 +92,15 @@ def suche(wort):
|
|
| 88 |
trans_lines = []
|
| 89 |
if str(row.get('Tr', '')).strip(): trans_lines.append(f"<div style='margin-bottom:2px;'><b>TR:</b> {markiere_rot(row['Tr'], wort)}</div>")
|
| 90 |
if str(row.get('De', '')).strip(): trans_lines.append(f"<div style='margin-bottom:2px;'><b>DE:</b> {markiere_rot(row['De'], wort)}</div>")
|
| 91 |
-
|
| 92 |
-
html_output += f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
return html_output
|
| 94 |
|
| 95 |
logo_data = get_base64_image(LOGO_NAME)
|
|
@@ -101,20 +112,17 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_sp
|
|
| 101 |
gr.HTML(f'<div style="text-align:center;"><img src="{logo_data}" width="420" style="margin: 0 auto; display: block;"></div>')
|
| 102 |
gr.HTML('<h1 style="text-align:center; margin-top: 10px;">DEZD Kırmancki Qesebend</h1>')
|
| 103 |
|
| 104 |
-
#
|
| 105 |
-
|
| 106 |
-
|
| 107 |
|
| 108 |
suche_input = gr.Textbox(label="Cıgêyre / Ara", placeholder="Kelime gir...", autofocus=True, elem_id="search_input")
|
| 109 |
-
result_output = gr.HTML()
|
| 110 |
|
| 111 |
gr.HTML("<div style='text-align:center; margin-top: 50px; padding: 20px; border-top: 1px solid #eee; color: #555;'><p>📩 <a href='mailto:info@manidar.org'>Xate vace</a> | 💬 <a href='mailto:info@manidar.org'>Feedback</a></p><p style='margin-top: 15px; font-size: 1.1em;'><b>Raresnayoğe: Gülten Karaca</b></p></div>")
|
| 112 |
|
| 113 |
suche_input.change(fn=suche, inputs=suche_input, outputs=result_output)
|
| 114 |
-
|
| 115 |
-
# Lädt Header-Daten (Stats & Wort) beim Start
|
| 116 |
-
demo.load(fn=get_dynamic_header, outputs=[stats_box, wotd_box])
|
| 117 |
|
| 118 |
-
# WICHTIG für Hugging Face: server_name="0.0.0.0"
|
| 119 |
if __name__ == "__main__":
|
| 120 |
-
demo.launch(
|
|
|
|
| 21 |
try:
|
| 22 |
content = raw_data.decode(encoding)
|
| 23 |
content = html.unescape(content)
|
| 24 |
+
# FIX: skiprows=32 entfernt, um alle 13.000+ Zeilen zu laden
|
| 25 |
+
df = pd.read_csv(io.StringIO(content), sep=",", on_bad_lines='skip', engine='python', quoting=3, header=None)
|
| 26 |
if len(df.columns) >= 3:
|
| 27 |
df = df.rename(columns={0: "Kirm", 1: "Tr", 2: "De", 3: "En"})
|
| 28 |
df = df.fillna("")
|
|
|
|
| 46 |
pattern = re.compile(re.escape(str(suchwort)), re.IGNORECASE)
|
| 47 |
return pattern.sub(lambda m: f"<span style='color:#e53935; font-weight:bold;'>{m.group(0)}</span>", text_str)
|
| 48 |
|
| 49 |
+
# FIX: Lädt Statistiken und Wort des Tages korrekt
|
| 50 |
+
def get_header_content():
|
| 51 |
if DF_GLOBAL is None or DF_GLOBAL.empty:
|
| 52 |
return "⚠️ Veriler yüklenemedi.", ""
|
| 53 |
+
|
| 54 |
total = len(DF_GLOBAL)
|
| 55 |
seed = int(datetime.now().strftime("%Y%m%d"))
|
| 56 |
+
wotd_row = DF_GLOBAL.sample(n=1, random_state=seed).iloc[0]
|
| 57 |
|
| 58 |
+
stats_html = f"<div style='text-align:center; margin-bottom: 10px; color: #555;'>📊 **{total}** Qesey u Ornagi (Kelimeler ve Örnekler)</div>"
|
| 59 |
|
| 60 |
langs = []
|
| 61 |
if str(wotd_row.get('Tr', '')).strip(): langs.append(f"🇹🇷 {wotd_row['Tr']}")
|
| 62 |
if str(wotd_row.get('De', '')).strip(): langs.append(f"🇩🇪 {wotd_row['De']}")
|
|
|
|
|
|
|
| 63 |
|
| 64 |
wotd_html = f"""
|
| 65 |
<div style='background-color: #f1f4ff; color: #1a237e; padding: 20px; border-radius: 12px; border-left: 8px solid #3f51b5; margin: 15px 0; border: 1px solid #d1d9ff;'>
|
| 66 |
<small style='color: #3f51b5; text-transform: uppercase; font-weight: bold;'>ROCA QESEY (Günün Kelimesi):</small><br>
|
| 67 |
<div style='margin-top: 10px;'>
|
| 68 |
<b style='font-size: 2em;'>{wotd_row['Kirm']}</b><br>
|
| 69 |
+
<div style='font-size: 1.1em; margin-top: 5px; color: #303f9f;'>{"<br>".join(langs)}</div>
|
| 70 |
</div>
|
| 71 |
</div>
|
| 72 |
"""
|
| 73 |
+
return stats_html, wotd_html
|
| 74 |
|
| 75 |
js_speak = "function speak(text) { window.speechSynthesis.cancel(); const msg = new SpeechSynthesisUtterance(text); msg.lang = 'tr-TR'; msg.rate = 0.5; window.speechSynthesis.speak(msg); }"
|
| 76 |
|
| 77 |
+
# Suche bleibt wie im Original
|
| 78 |
def suche(wort):
|
| 79 |
wort = str(wort).strip()
|
| 80 |
if len(wort) < 2: return "<p style='text-align:center; color:#777;'>✍️ Bınusnê...</p>"
|
| 81 |
if DF_GLOBAL is None: return "Hata."
|
| 82 |
+
|
| 83 |
mask = DF_GLOBAL.astype(str).apply(lambda x: x.str.contains(wort, case=False, na=False)).any(axis=1)
|
| 84 |
ergebnis = DF_GLOBAL[mask].head(50)
|
| 85 |
+
|
| 86 |
if ergebnis.empty: return "<h3 style='text-align:center;'>❌ Çino.</h3>"
|
| 87 |
+
|
| 88 |
html_output = ""
|
| 89 |
for _, row in ergebnis.iterrows():
|
| 90 |
clean_text = str(row['Kirm']).replace("'", "\\'")
|
|
|
|
| 92 |
trans_lines = []
|
| 93 |
if str(row.get('Tr', '')).strip(): trans_lines.append(f"<div style='margin-bottom:2px;'><b>TR:</b> {markiere_rot(row['Tr'], wort)}</div>")
|
| 94 |
if str(row.get('De', '')).strip(): trans_lines.append(f"<div style='margin-bottom:2px;'><b>DE:</b> {markiere_rot(row['De'], wort)}</div>")
|
| 95 |
+
|
| 96 |
+
html_output += f"""
|
| 97 |
+
<div style='margin-bottom: 25px; border-bottom: 1px solid #eee; padding-bottom: 15px;'>
|
| 98 |
+
<div style='display: flex; align-items: center; margin-bottom: 8px;'>
|
| 99 |
+
<h2 style='color:#1a237e; margin: 0 12px 0 0;'>☀️ {kirm}</h2>
|
| 100 |
+
<button onclick="speak('{clean_text}')" style='cursor:pointer; background:transparent; border:none; font-size:1.3em; color:#1a237e;'>🎧</button>
|
| 101 |
+
</div>
|
| 102 |
+
<div style='color:#444; line-height: 1.6;'>{"".join(trans_lines)}</div>
|
| 103 |
+
</div>"""
|
| 104 |
return html_output
|
| 105 |
|
| 106 |
logo_data = get_base64_image(LOGO_NAME)
|
|
|
|
| 112 |
gr.HTML(f'<div style="text-align:center;"><img src="{logo_data}" width="420" style="margin: 0 auto; display: block;"></div>')
|
| 113 |
gr.HTML('<h1 style="text-align:center; margin-top: 10px;">DEZD Kırmancki Qesebend</h1>')
|
| 114 |
|
| 115 |
+
# FIX: Diese zwei Zeilen verhindern den KaTeX/Code-Fehler
|
| 116 |
+
stats_display = gr.Markdown()
|
| 117 |
+
wotd_display = gr.HTML(latex_delimiters=[])
|
| 118 |
|
| 119 |
suche_input = gr.Textbox(label="Cıgêyre / Ara", placeholder="Kelime gir...", autofocus=True, elem_id="search_input")
|
| 120 |
+
result_output = gr.HTML(latex_delimiters=[])
|
| 121 |
|
| 122 |
gr.HTML("<div style='text-align:center; margin-top: 50px; padding: 20px; border-top: 1px solid #eee; color: #555;'><p>📩 <a href='mailto:info@manidar.org'>Xate vace</a> | 💬 <a href='mailto:info@manidar.org'>Feedback</a></p><p style='margin-top: 15px; font-size: 1.1em;'><b>Raresnayoğe: Gülten Karaca</b></p></div>")
|
| 123 |
|
| 124 |
suche_input.change(fn=suche, inputs=suche_input, outputs=result_output)
|
| 125 |
+
demo.load(fn=get_header_content, outputs=[stats_display, wotd_display])
|
|
|
|
|
|
|
| 126 |
|
|
|
|
| 127 |
if __name__ == "__main__":
|
| 128 |
+
demo.launch()
|