Manidar commited on
Commit
befc3af
·
verified ·
1 Parent(s): 66ab539

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -59
app.py CHANGED
@@ -9,7 +9,7 @@ import base64
9
  import html
10
 
11
  # Konfiguration
12
- DATA_URL = "https://huggingface.co/datasets/Manidar/DEZD-Dictionary-Kirmancki/resolve/main/kirmancki%20qesebend%20dictionary.csv"
13
  LOGO_NAME = "logo.jpg"
14
 
15
  def load_data():
@@ -45,8 +45,8 @@ 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
- # Diese Funktion wird nun bei jedem Laden der Seite aufgerufen
49
- def get_header_data_dynamic():
50
  if DF_GLOBAL is None or DF_GLOBAL.empty:
51
  return "⚠️ Veriler yüklenemedi.", ""
52
  total = len(DF_GLOBAL)
@@ -72,65 +72,28 @@ def get_header_data_dynamic():
72
  """
73
  return f"<div style='text-align:center; margin-bottom: 10px; color: #555;'>{stats}</div>", wotd_html
74
 
75
- js_speak = """
76
- function speak(text) {
77
- window.speechSynthesis.cancel();
78
- const msg = new SpeechSynthesisUtterance(text);
79
- msg.lang = 'tr-TR';
80
- msg.rate = 0.5;
81
- window.speechSynthesis.speak(msg);
82
- }
83
- """
84
 
85
  def suche(wort):
86
  wort = str(wort).strip()
87
  if len(wort) < 2: return "<p style='text-align:center; color:#777;'>✍️ Bınusnê...</p>"
88
  if DF_GLOBAL is None: return "Hata."
89
-
90
  mask = DF_GLOBAL.astype(str).apply(lambda x: x.str.contains(wort, case=False, na=False)).any(axis=1)
91
  ergebnis = DF_GLOBAL[mask].head(50)
92
-
93
  if ergebnis.empty: return "<h3 style='text-align:center;'>❌ Çino.</h3>"
94
-
95
  html_output = ""
96
  for _, row in ergebnis.iterrows():
97
  clean_text = str(row['Kirm']).replace("'", "\\'")
98
  kirm = markiere_rot(row['Kirm'], wort)
99
-
100
  trans_lines = []
101
- if str(row.get('Tr', '')).strip():
102
- trans_lines.append(f"<div style='margin-bottom:2px;'><b>TR:</b> {markiere_rot(row['Tr'], wort)}</div>")
103
- if str(row.get('De', '')).strip():
104
- trans_lines.append(f"<div style='margin-bottom:2px;'><b>DE:</b> {markiere_rot(row['De'], wort)}</div>")
105
- if str(row.get('En', '')).strip():
106
- trans_lines.append(f"<div><b>EN:</b> {markiere_rot(row['En'], wort)}</div>")
107
-
108
- html_output += f"""
109
- <div style='margin-bottom: 25px; border-bottom: 1px solid #eee; padding-bottom: 15px;'>
110
- <div style='display: flex; align-items: center; margin-bottom: 8px;'>
111
- <h2 style='color:#1a237e; margin: 0 12px 0 0;'>☀️ {kirm}</h2>
112
- <button onclick="speak('{clean_text}')" title="Gose de" style='cursor:pointer; background:transparent; border:none; font-size:1.3em; color:#1a237e;'>🎧</button>
113
- </div>
114
- <div style='color:#444; line-height: 1.6;'>
115
- {"".join(trans_lines)}
116
- </div>
117
- </div>
118
- """
119
  return html_output
120
 
121
  logo_data = get_base64_image(LOGO_NAME)
122
-
123
- custom_css = """
124
- #search_input input {
125
- border: 1px solid black !important;
126
- box-shadow: none !important;
127
- outline: 2px solid transparent !important;
128
- }
129
- #search_input input:focus {
130
- border: 1.5px solid black !important;
131
- }
132
- footer { display: none !important; }
133
- """
134
 
135
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_speak}</script>", css=custom_css) as demo:
136
  with gr.Column():
@@ -138,24 +101,20 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_sp
138
  gr.HTML(f'<div style="text-align:center;"><img src="{logo_data}" width="420" style="margin: 0 auto; display: block;"></div>')
139
  gr.HTML('<h1 style="text-align:center; margin-top: 10px;">DEZD Kırmancki Qesebend</h1>')
140
 
141
- # Diese Platzhalter werden beim Laden gefüllt
142
- stats_display = gr.HTML()
143
- wotd_display = gr.HTML()
144
 
145
  suche_input = gr.Textbox(label="Cıgêyre / Ara", placeholder="Kelime gir...", autofocus=True, elem_id="search_input")
146
  result_output = gr.HTML()
147
 
148
- gr.HTML("""
149
- <div style='text-align:center; margin-top: 50px; padding: 20px; border-top: 1px solid #eee; color: #555;'>
150
- <p>📩 <a href="mailto:info@manidar.org">Xate vace</a> | 💬 <a href="mailto:info@manidar.org">Feedback</a></p>
151
- <p style='margin-top: 15px; font-size: 1.1em;'><b>Raresnayoğe: Gülten Karaca</b></p>
152
- </div>
153
- """)
154
 
155
- # Events
156
  suche_input.change(fn=suche, inputs=suche_input, outputs=result_output)
157
 
158
- # DAS IST NEU: Lädt Statistiken und Wort des Tages dynamisch beim Seitenaufruf
159
- demo.load(fn=get_header_data_dynamic, outputs=[stats_display, wotd_display])
160
 
161
- demo.launch()
 
 
 
9
  import html
10
 
11
  # Konfiguration
12
+ DATA_URL = "https://huggingface.co"
13
  LOGO_NAME = "logo.jpg"
14
 
15
  def load_data():
 
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
+ # NEU: Diese Funktion aktualisiert das Wort des Tages bei jedem Laden
49
+ def get_dynamic_header():
50
  if DF_GLOBAL is None or DF_GLOBAL.empty:
51
  return "⚠️ Veriler yüklenemedi.", ""
52
  total = len(DF_GLOBAL)
 
72
  """
73
  return f"<div style='text-align:center; margin-bottom: 10px; color: #555;'>{stats}</div>", 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
  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("'", "\\'")
87
  kirm = markiere_rot(row['Kirm'], 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
+ if str(row.get('En', '')).strip(): trans_lines.append(f"<div><b>EN:</b> {markiere_rot(row['En'], wort)}</div>")
92
+ 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>"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
  return html_output
94
 
95
  logo_data = get_base64_image(LOGO_NAME)
96
+ custom_css = "#search_input input { border: 1px solid black !important; box-shadow: none !important; } footer { display: none !important; }"
 
 
 
 
 
 
 
 
 
 
 
97
 
98
  with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo"), head=f"<script>{js_speak}</script>", css=custom_css) as demo:
99
  with gr.Column():
 
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
+ # Platzhalter für dynamische Inhalte
105
+ stats_box = gr.HTML()
106
+ wotd_box = gr.HTML()
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(server_name="0.0.0.0", server_port=7860)