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=
|
| 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 |
-
|
| 33 |
|
| 34 |
DF_GLOBAL = load_data()
|
| 35 |
|
|
@@ -46,39 +46,39 @@ 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 |
-
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 |
-
|
| 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;'>{
|
| 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 |
-
# 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)
|
|
@@ -112,9 +112,10 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_sp
|
|
| 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 |
-
|
|
|
|
| 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=[])
|
|
@@ -122,7 +123,7 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_sp
|
|
| 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 |
-
|
|
|
|
| 126 |
|
| 127 |
-
|
| 128 |
-
demo.launch()
|
|
|
|
| 21 |
try:
|
| 22 |
content = raw_data.decode(encoding)
|
| 23 |
content = html.unescape(content)
|
| 24 |
+
# Sep=None mit Python engine erkennt automatisch Komma oder Semikolon
|
| 25 |
+
df = pd.read_csv(io.StringIO(content), sep=None, skiprows=32, 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 |
+
except: pass
|
| 32 |
+
return pd.DataFrame(columns=["Kirm", "Tr", "De", "En"])
|
| 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 |
+
def get_header_data_dynamic():
|
|
|
|
| 50 |
if DF_GLOBAL is None or DF_GLOBAL.empty:
|
| 51 |
+
return "⚠️ Veriler yüklenemedi.", "<p>Hata: Veri seti boş.</p>"
|
| 52 |
|
| 53 |
total = len(DF_GLOBAL)
|
| 54 |
seed = int(datetime.now().strftime("%Y%m%d"))
|
| 55 |
+
# Fix für Wort-Auswahl
|
| 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 = []
|
| 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 |
+
lang_html = "<br>".join(langs)
|
| 64 |
|
| 65 |
wotd_html = f"""
|
| 66 |
<div style='background-color: #f1f4ff; color: #1a237e; padding: 20px; border-radius: 12px; border-left: 8px solid #3f51b5; margin: 15px 0; border: 1px solid #d1d9ff;'>
|
| 67 |
<small style='color: #3f51b5; text-transform: uppercase; font-weight: bold;'>ROCA QESEY (Günün Kelimesi):</small><br>
|
| 68 |
<div style='margin-top: 10px;'>
|
| 69 |
<b style='font-size: 2em;'>{wotd_row['Kirm']}</b><br>
|
| 70 |
+
<div style='font-size: 1.1em; margin-top: 5px; color: #303f9f;'>{lang_html}</div>
|
| 71 |
</div>
|
| 72 |
</div>
|
| 73 |
"""
|
| 74 |
+
return stats, wotd_html
|
| 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 or DF_GLOBAL.empty: return "Hata: Veri yüklenemedi."
|
| 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)
|
|
|
|
| 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 |
+
# Markdown für stats (bessere Performance), HTML für Wort des Tages
|
| 116 |
+
stats_display = gr.Markdown(value="Veriler yükleniyor...")
|
| 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=[])
|
|
|
|
| 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 |
+
# Lädt Header-Daten beim Starten des Browsers
|
| 127 |
+
demo.load(fn=get_header_data_dynamic, outputs=[stats_display, wotd_display])
|
| 128 |
|
| 129 |
+
demo.launch()
|
|
|