Update app.py
Browse files
app.py
CHANGED
|
@@ -21,15 +21,15 @@ def load_data():
|
|
| 21 |
try:
|
| 22 |
content = raw_data.decode(encoding)
|
| 23 |
content = html.unescape(content)
|
| 24 |
-
#
|
| 25 |
-
df = pd.read_csv(io.StringIO(content), sep=None,
|
| 26 |
if len(df.columns) >= 3:
|
| 27 |
df = df.rename(columns={0: "Kirm", 1: "Tr", 2: "De", 3: "En"})
|
| 28 |
df = df.fillna("")
|
| 29 |
return df
|
| 30 |
except: continue
|
| 31 |
-
|
| 32 |
-
return
|
| 33 |
|
| 34 |
DF_GLOBAL = load_data()
|
| 35 |
|
|
@@ -46,15 +46,13 @@ def markiere_rot(text, suchwort):
|
|
| 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 |
-
|
|
|
|
| 50 |
if DF_GLOBAL is None or DF_GLOBAL.empty:
|
| 51 |
-
return "⚠️ Veriler yüklenemedi.", "
|
| 52 |
-
|
| 53 |
total = len(DF_GLOBAL)
|
| 54 |
seed = int(datetime.now().strftime("%Y%m%d"))
|
| 55 |
-
|
| 56 |
-
wotd_row = DF_GLOBAL.sample(n=1, random_state=seed).iloc[0]
|
| 57 |
-
|
| 58 |
stats = f"📊 **{total}** Qesey u Ornagi (Kelimeler ve Örnekler)"
|
| 59 |
|
| 60 |
langs = []
|
|
@@ -75,16 +73,14 @@ def get_header_data_dynamic():
|
|
| 75 |
|
| 76 |
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); }"
|
| 77 |
|
|
|
|
| 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
|
| 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,38 +88,37 @@ def suche(wort):
|
|
| 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)
|
| 107 |
-
custom_css = "#search_input input { border: 1px solid black !important; box-shadow: none !important; } footer { display: none !important; }"
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_speak}</script>", css=custom_css) as demo:
|
| 110 |
with gr.Column():
|
| 111 |
if logo_data:
|
| 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 |
-
#
|
| 116 |
-
stats_display = gr.Markdown(
|
| 117 |
-
# latex_delimiters=[] entfernt die KaTeX Fehleranzeigen
|
| 118 |
wotd_display = gr.HTML(latex_delimiters=[])
|
| 119 |
|
| 120 |
suche_input = gr.Textbox(label="Cıgêyre / Ara", placeholder="Kelime gir...", autofocus=True, elem_id="search_input")
|
|
|
|
| 121 |
result_output = gr.HTML(latex_delimiters=[])
|
| 122 |
|
| 123 |
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>")
|
| 124 |
|
| 125 |
suche_input.change(fn=suche, inputs=suche_input, outputs=result_output)
|
| 126 |
-
|
| 127 |
-
|
|
|
|
| 128 |
|
| 129 |
-
|
|
|
|
|
|
| 21 |
try:
|
| 22 |
content = raw_data.decode(encoding)
|
| 23 |
content = html.unescape(content)
|
| 24 |
+
# FIX: skiprows entfernt, damit alle 13.000+ Wörter geladen werden
|
| 25 |
+
df = pd.read_csv(io.StringIO(content), sep=None, 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("")
|
| 29 |
return df
|
| 30 |
except: continue
|
| 31 |
+
return None
|
| 32 |
+
except: return None
|
| 33 |
|
| 34 |
DF_GLOBAL = load_data()
|
| 35 |
|
|
|
|
| 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 |
+
# Wort des Tages Funktion (Logik aus deinem alten Code)
|
| 50 |
+
def get_header_data():
|
| 51 |
if DF_GLOBAL is None or DF_GLOBAL.empty:
|
| 52 |
+
return "⚠️ Veriler yüklenemedi.", ""
|
|
|
|
| 53 |
total = len(DF_GLOBAL)
|
| 54 |
seed = int(datetime.now().strftime("%Y%m%d"))
|
| 55 |
+
wotd_row = DF_GLOBAL.sample(n=1, random_state=seed).iloc[0].to_dict()
|
|
|
|
|
|
|
| 56 |
stats = f"📊 **{total}** Qesey u Ornagi (Kelimeler ve Örnekler)"
|
| 57 |
|
| 58 |
langs = []
|
|
|
|
| 73 |
|
| 74 |
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); }"
|
| 75 |
|
| 76 |
+
# Suche (Original-Logik)
|
| 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 |
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 |
+
html_output += f"<div style='margin-bottom: 25px; border-bottom: 1px solid #eee; padding-bottom: 15px;'><div style='display: flex; align-items: center; margin-bottom: 8px;'><h2 style='color:#1a237e; margin: 0 12px 0 0;'>☀️ {kirm}</h2><button onclick=\"speak('{clean_text}')\" style='cursor:pointer; background:transparent; border:none; font-size:1.3em; color:#1a237e;'>🎧</button></div><div style='color:#444; line-height: 1.6;'>{''.join(trans_lines)}</div></div>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
return html_output
|
| 93 |
|
| 94 |
logo_data = get_base64_image(LOGO_NAME)
|
|
|
|
| 95 |
|
| 96 |
+
custom_css = """
|
| 97 |
+
#search_input input { border: 1px solid black !important; box-shadow: none !important; }
|
| 98 |
+
footer { display: none !important; }
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
# START INTERFACE
|
| 102 |
with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_speak}</script>", css=custom_css) as demo:
|
| 103 |
with gr.Column():
|
| 104 |
if logo_data:
|
| 105 |
gr.HTML(f'<div style="text-align:center;"><img src="{logo_data}" width="420" style="margin: 0 auto; display: block;"></div>')
|
| 106 |
gr.HTML('<h1 style="text-align:center; margin-top: 10px;">DEZD Kırmancki Qesebend</h1>')
|
| 107 |
|
| 108 |
+
# FIX: Diese Platzhalter laden die Daten dynamisch ohne KaTeX-Fehler
|
| 109 |
+
stats_display = gr.Markdown()
|
|
|
|
| 110 |
wotd_display = gr.HTML(latex_delimiters=[])
|
| 111 |
|
| 112 |
suche_input = gr.Textbox(label="Cıgêyre / Ara", placeholder="Kelime gir...", autofocus=True, elem_id="search_input")
|
| 113 |
+
# FIX: latex_delimiters=[] stoppt window.hubConfig Fehler in der Suche
|
| 114 |
result_output = gr.HTML(latex_delimiters=[])
|
| 115 |
|
| 116 |
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>")
|
| 117 |
|
| 118 |
suche_input.change(fn=suche, inputs=suche_input, outputs=result_output)
|
| 119 |
+
|
| 120 |
+
# Lädt Wort des Tages und Statistiken beim Seitenaufruf
|
| 121 |
+
demo.load(fn=get_header_data, outputs=[stats_display, wotd_display])
|
| 122 |
|
| 123 |
+
if __name__ == "__main__":
|
| 124 |
+
demo.launch()
|