Update app.py
#2
by Manidar - opened
app.py
CHANGED
|
@@ -21,8 +21,8 @@ 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("")
|
|
@@ -31,7 +31,6 @@ def load_data():
|
|
| 31 |
return None
|
| 32 |
except: return None
|
| 33 |
|
| 34 |
-
# Global laden
|
| 35 |
DF_GLOBAL = load_data()
|
| 36 |
|
| 37 |
def get_base64_image(path):
|
|
@@ -47,20 +46,13 @@ def markiere_rot(text, suchwort):
|
|
| 47 |
pattern = re.compile(re.escape(str(suchwort)), re.IGNORECASE)
|
| 48 |
return pattern.sub(lambda m: f"<span style='color:#e53935; font-weight:bold;'>{m.group(0)}</span>", text_str)
|
| 49 |
|
| 50 |
-
#
|
| 51 |
def get_header_data_dynamic():
|
| 52 |
-
# Falls DF_GLOBAL leer ist, versuchen wir es hier erneut
|
| 53 |
-
global DF_GLOBAL
|
| 54 |
if DF_GLOBAL is None or DF_GLOBAL.empty:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
if DF_GLOBAL is None or DF_GLOBAL.empty:
|
| 58 |
-
return "⚠️ Veriler yüklenemedi (CSV fehlerhaft).", "Daten konnten nicht geladen werden."
|
| 59 |
-
|
| 60 |
total = len(DF_GLOBAL)
|
| 61 |
seed = int(datetime.now().strftime("%Y%m%d"))
|
| 62 |
wotd_row = DF_GLOBAL.sample(n=1, random_state=seed).iloc[0].to_dict()
|
| 63 |
-
|
| 64 |
stats = f"📊 **{total}** Qesey u Ornagi (Kelimeler ve Örnekler)"
|
| 65 |
|
| 66 |
langs = []
|
|
@@ -79,18 +71,23 @@ def get_header_data_dynamic():
|
|
| 79 |
"""
|
| 80 |
return stats, wotd_html
|
| 81 |
|
| 82 |
-
js_speak = "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
def suche(wort):
|
| 85 |
wort = str(wort).strip()
|
| 86 |
if len(wort) < 2: return "<p style='text-align:center; color:#777;'>✍️ Bınusnê...</p>"
|
| 87 |
-
if DF_GLOBAL is None
|
| 88 |
-
|
| 89 |
mask = DF_GLOBAL.astype(str).apply(lambda x: x.str.contains(wort, case=False, na=False)).any(axis=1)
|
| 90 |
ergebnis = DF_GLOBAL[mask].head(50)
|
| 91 |
-
|
| 92 |
if ergebnis.empty: return "<h3 style='text-align:center;'>❌ Çino.</h3>"
|
| 93 |
-
|
| 94 |
html_output = ""
|
| 95 |
for _, row in ergebnis.iterrows():
|
| 96 |
clean_text = str(row['Kirm']).replace("'", "\\'")
|
|
@@ -110,9 +107,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_sp
|
|
| 110 |
gr.HTML(f'<div style="text-align:center;"><img src="{logo_data}" width="420" style="margin: 0 auto; display: block;"></div>')
|
| 111 |
gr.HTML('<h1 style="text-align:center; margin-top: 10px;">DEZD Kırmancki Qesebend</h1>')
|
| 112 |
|
| 113 |
-
#
|
| 114 |
stats_display = gr.Markdown()
|
| 115 |
-
# latex_delimiters=[] stoppt den KaTeX / window.hubConfig Fehler
|
| 116 |
wotd_display = gr.HTML(latex_delimiters=[])
|
| 117 |
|
| 118 |
suche_input = gr.Textbox(label="Cıgêyre / Ara", placeholder="Kelime gir...", autofocus=True, elem_id="search_input")
|
|
@@ -120,9 +116,8 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_sp
|
|
| 120 |
|
| 121 |
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>")
|
| 122 |
|
| 123 |
-
# Event-Bindungen
|
| 124 |
suche_input.change(fn=suche, inputs=suche_input, outputs=result_output)
|
|
|
|
| 125 |
demo.load(fn=get_header_data_dynamic, outputs=[stats_display, wotd_display])
|
| 126 |
|
| 127 |
-
|
| 128 |
-
demo.launch()
|
|
|
|
| 21 |
try:
|
| 22 |
content = raw_data.decode(encoding)
|
| 23 |
content = html.unescape(content)
|
| 24 |
+
# Dein Original-Ladebefehl
|
| 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("")
|
|
|
|
| 31 |
return None
|
| 32 |
except: return None
|
| 33 |
|
|
|
|
| 34 |
DF_GLOBAL = load_data()
|
| 35 |
|
| 36 |
def get_base64_image(path):
|
|
|
|
| 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 |
+
# DIESE FUNKTION ERSETZT JETZT DIE STARREN VARIABLEN
|
| 50 |
def get_header_data_dynamic():
|
|
|
|
|
|
|
| 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 = []
|
|
|
|
| 71 |
"""
|
| 72 |
return stats, wotd_html
|
| 73 |
|
| 74 |
+
js_speak = """
|
| 75 |
+
function speak(text) {
|
| 76 |
+
window.speechSynthesis.cancel();
|
| 77 |
+
const msg = new SpeechSynthesisUtterance(text);
|
| 78 |
+
msg.lang = 'tr-TR';
|
| 79 |
+
msg.rate = 0.5;
|
| 80 |
+
window.speechSynthesis.speak(msg);
|
| 81 |
+
}
|
| 82 |
+
"""
|
| 83 |
|
| 84 |
def suche(wort):
|
| 85 |
wort = str(wort).strip()
|
| 86 |
if len(wort) < 2: return "<p style='text-align:center; color:#777;'>✍️ Bınusnê...</p>"
|
| 87 |
+
if DF_GLOBAL is None: return "Hata."
|
|
|
|
| 88 |
mask = DF_GLOBAL.astype(str).apply(lambda x: x.str.contains(wort, case=False, na=False)).any(axis=1)
|
| 89 |
ergebnis = DF_GLOBAL[mask].head(50)
|
|
|
|
| 90 |
if ergebnis.empty: return "<h3 style='text-align:center;'>❌ Çino.</h3>"
|
|
|
|
| 91 |
html_output = ""
|
| 92 |
for _, row in ergebnis.iterrows():
|
| 93 |
clean_text = str(row['Kirm']).replace("'", "\\'")
|
|
|
|
| 107 |
gr.HTML(f'<div style="text-align:center;"><img src="{logo_data}" width="420" style="margin: 0 auto; display: block;"></div>')
|
| 108 |
gr.HTML('<h1 style="text-align:center; margin-top: 10px;">DEZD Kırmancki Qesebend</h1>')
|
| 109 |
|
| 110 |
+
# Diese Felder werden jetzt beim Laden gefüllt
|
| 111 |
stats_display = gr.Markdown()
|
|
|
|
| 112 |
wotd_display = gr.HTML(latex_delimiters=[])
|
| 113 |
|
| 114 |
suche_input = gr.Textbox(label="Cıgêyre / Ara", placeholder="Kelime gir...", autofocus=True, elem_id="search_input")
|
|
|
|
| 116 |
|
| 117 |
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>")
|
| 118 |
|
|
|
|
| 119 |
suche_input.change(fn=suche, inputs=suche_input, outputs=result_output)
|
| 120 |
+
# DAS LÄDT DIE DATEN DYNAMISCH
|
| 121 |
demo.load(fn=get_header_data_dynamic, outputs=[stats_display, wotd_display])
|
| 122 |
|
| 123 |
+
demo.launch()
|
|
|