Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,13 +21,13 @@ Regeln:
|
|
| 21 |
- Alles ist eine "Journey", ein "Gamechanger" oder eine "powerful lesson"
|
| 22 |
- Nutze mindestens 3 Emojis strategisch
|
| 23 |
- ErwΓ€hne "Growth", "Mindset", "Passion" oder "Impact" wo immer mΓΆglich
|
| 24 |
-
-
|
| 25 |
- Endet mit einer rhetorischen Frage an die Community
|
| 26 |
-
- Benutze dramatische
|
| 27 |
- Alles ist ausnahmslos positiv, auch wenn das Original negativ ist
|
| 28 |
- Hashtags am Ende sind Pflicht (mindestens 5)
|
| 29 |
-
- Klingt wie jemand, der gerade ein Buch
|
| 30 |
-
- Formatiere mit Markdown: ErΓΆffnungssatz als ## Ueberschrift,
|
| 31 |
|
| 32 |
Antworte NUR mit dem LinkedIn-Post in Markdown. Kein Vorwort, keine ErklΓ€rung."""
|
| 33 |
|
|
@@ -35,7 +35,7 @@ PROMPT_FROM_LINKEDIN = """Du bist ein gnadenloser semantischer Reduzierer. Du ha
|
|
| 35 |
|
| 36 |
Regeln:
|
| 37 |
- EIN Satz. Nicht zwei. Einer.
|
| 38 |
-
-
|
| 39 |
- Null Emotion, null Wertung, null Kontext der niemanden interessiert
|
| 40 |
- Streiche alles was keine neue Information trΓ€gt
|
| 41 |
- Wenn der gesamte Post nur bedeutet "Ich hab heute Kaffee getrunken" schreib genau das
|
|
@@ -74,7 +74,7 @@ Rules:
|
|
| 74 |
# ββ HF Dataset Persistenz ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 75 |
|
| 76 |
def _fetch_dataset() -> list:
|
| 77 |
-
"""
|
| 78 |
if not DATASET_REPO or not HF_TOKEN:
|
| 79 |
return []
|
| 80 |
try:
|
|
@@ -97,10 +97,10 @@ def _fetch_dataset() -> list:
|
|
| 97 |
return []
|
| 98 |
|
| 99 |
|
| 100 |
-
def _push_entry(entry: dict):
|
| 101 |
-
"""HΓ€ngt einen neuen Eintrag an das JSONL im HF Dataset an."""
|
| 102 |
if not DATASET_REPO or not HF_TOKEN:
|
| 103 |
-
return
|
| 104 |
try:
|
| 105 |
existing = _fetch_dataset()
|
| 106 |
existing.append(entry)
|
|
@@ -118,15 +118,16 @@ def _push_entry(entry: dict):
|
|
| 118 |
commit_message=f"Add entry {datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}",
|
| 119 |
)
|
| 120 |
os.unlink(tmp_path)
|
| 121 |
-
except Exception:
|
| 122 |
-
|
|
|
|
| 123 |
|
| 124 |
|
| 125 |
def _dataset_count() -> int:
|
| 126 |
return len(_fetch_dataset())
|
| 127 |
|
| 128 |
|
| 129 |
-
# ββ Lokales Leaderboard (schneller Cache
|
| 130 |
|
| 131 |
def _load_lb() -> list:
|
| 132 |
try:
|
|
@@ -309,7 +310,7 @@ def get_bingo(text):
|
|
| 309 |
|
| 310 |
# HF Dataset (async best-effort)
|
| 311 |
entry = {
|
| 312 |
-
"timestamp": datetime.datetime.
|
| 313 |
"post_text": text,
|
| 314 |
"total_score": total,
|
| 315 |
"max_score": max_s,
|
|
@@ -317,9 +318,11 @@ def get_bingo(text):
|
|
| 317 |
"verdict": verdict,
|
| 318 |
"metrics": metrics,
|
| 319 |
}
|
| 320 |
-
_push_entry(entry)
|
| 321 |
-
|
| 322 |
-
|
|
|
|
|
|
|
| 323 |
except Exception as e:
|
| 324 |
last_err = e
|
| 325 |
return (f"<p style='color:#c00;font-size:.85rem;padding:8px;'>Analyse fehlgeschlagen: {last_err}</p>",
|
|
@@ -468,7 +471,7 @@ button.secondary:hover { background:var(--li-blue-light) !important; }
|
|
| 468 |
|
| 469 |
# ββ UI βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 470 |
|
| 471 |
-
with gr.Blocks(title="LinkedIn Translator"
|
| 472 |
|
| 473 |
direction_state = gr.State("to_linkedin")
|
| 474 |
|
|
@@ -487,7 +490,7 @@ with gr.Blocks(title="LinkedIn Translator", css=CSS) as demo:
|
|
| 487 |
with gr.Row(equal_height=True):
|
| 488 |
with gr.Column(scale=5):
|
| 489 |
input_box = gr.Textbox(label="βοΈ Normale Aussage",
|
| 490 |
-
placeholder="z.B. 'Ich hab heute meinen Kaffee
|
| 491 |
lines=10)
|
| 492 |
with gr.Column(scale=1, min_width=120):
|
| 493 |
gr.HTML("<div style='height:40px'></div>")
|
|
@@ -557,4 +560,4 @@ with gr.Blocks(title="LinkedIn Translator", css=CSS) as demo:
|
|
| 557 |
outputs=[direction_state, input_box, output_box, swap_btn, dir_label, markdown_out, bingo_out],
|
| 558 |
)
|
| 559 |
|
| 560 |
-
demo.launch()
|
|
|
|
| 21 |
- Alles ist eine "Journey", ein "Gamechanger" oder eine "powerful lesson"
|
| 22 |
- Nutze mindestens 3 Emojis strategisch
|
| 23 |
- ErwΓ€hne "Growth", "Mindset", "Passion" oder "Impact" wo immer mΓΆglich
|
| 24 |
+
- FΓΌge eine persΓΆnliche Anekdote hinzu, die niemand braucht
|
| 25 |
- Endet mit einer rhetorischen Frage an die Community
|
| 26 |
+
- Benutze dramatische ZeilenumbrΓΌche fΓΌr Effekt
|
| 27 |
- Alles ist ausnahmslos positiv, auch wenn das Original negativ ist
|
| 28 |
- Hashtags am Ende sind Pflicht (mindestens 5)
|
| 29 |
+
- Klingt wie jemand, der gerade ein Buch ΓΌber sich selbst schreiben wΓΌrde
|
| 30 |
+
- Formatiere mit Markdown: ErΓΆffnungssatz als ## Ueberschrift, SchlΓΌsselbegriffe wie **Gamechanger**, **Growth**, **Mindset**, **Journey** fett hervorheben, Abschnitte mit Leerzeilen trennen
|
| 31 |
|
| 32 |
Antworte NUR mit dem LinkedIn-Post in Markdown. Kein Vorwort, keine ErklΓ€rung."""
|
| 33 |
|
|
|
|
| 35 |
|
| 36 |
Regeln:
|
| 37 |
- EIN Satz. Nicht zwei. Einer.
|
| 38 |
+
- KΓΌrze bis es wehtut. Dann nochmal kΓΌrzen.
|
| 39 |
- Null Emotion, null Wertung, null Kontext der niemanden interessiert
|
| 40 |
- Streiche alles was keine neue Information trΓ€gt
|
| 41 |
- Wenn der gesamte Post nur bedeutet "Ich hab heute Kaffee getrunken" schreib genau das
|
|
|
|
| 74 |
# ββ HF Dataset Persistenz ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 75 |
|
| 76 |
def _fetch_dataset() -> list:
|
| 77 |
+
"""Laedt bestehende EintrΓ€ge aus dem HF Dataset Repo."""
|
| 78 |
if not DATASET_REPO or not HF_TOKEN:
|
| 79 |
return []
|
| 80 |
try:
|
|
|
|
| 97 |
return []
|
| 98 |
|
| 99 |
|
| 100 |
+
def _push_entry(entry: dict) -> str:
|
| 101 |
+
"""HΓ€ngt einen neuen Eintrag an das JSONL im HF Dataset an. Gibt Fehler oder leer zurΓΌck."""
|
| 102 |
if not DATASET_REPO or not HF_TOKEN:
|
| 103 |
+
return ""
|
| 104 |
try:
|
| 105 |
existing = _fetch_dataset()
|
| 106 |
existing.append(entry)
|
|
|
|
| 118 |
commit_message=f"Add entry {datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}",
|
| 119 |
)
|
| 120 |
os.unlink(tmp_path)
|
| 121 |
+
except Exception as e:
|
| 122 |
+
return str(e)
|
| 123 |
+
return ""
|
| 124 |
|
| 125 |
|
| 126 |
def _dataset_count() -> int:
|
| 127 |
return len(_fetch_dataset())
|
| 128 |
|
| 129 |
|
| 130 |
+
# ββ Lokales Leaderboard (schneller Cache fΓΌr UI) ββββββββββββββββββββββββββββββ
|
| 131 |
|
| 132 |
def _load_lb() -> list:
|
| 133 |
try:
|
|
|
|
| 310 |
|
| 311 |
# HF Dataset (async best-effort)
|
| 312 |
entry = {
|
| 313 |
+
"timestamp": datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
| 314 |
"post_text": text,
|
| 315 |
"total_score": total,
|
| 316 |
"max_score": max_s,
|
|
|
|
| 318 |
"verdict": verdict,
|
| 319 |
"metrics": metrics,
|
| 320 |
}
|
| 321 |
+
push_err = _push_entry(entry)
|
| 322 |
+
lb = _render_leaderboard()
|
| 323 |
+
if push_err:
|
| 324 |
+
lb += f'''<div style="background:#FFF0F0;border:1px solid #e88;border-left:4px solid #c00;border-radius:6px;padding:8px 12px;font-size:.78rem;color:#900;margin-top:8px;"><strong>⚠ Dataset-Push fehlgeschlagen:</strong> {push_err}</div>'''
|
| 325 |
+
return _render_bingo(data), lb
|
| 326 |
except Exception as e:
|
| 327 |
last_err = e
|
| 328 |
return (f"<p style='color:#c00;font-size:.85rem;padding:8px;'>Analyse fehlgeschlagen: {last_err}</p>",
|
|
|
|
| 471 |
|
| 472 |
# ββ UI βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 473 |
|
| 474 |
+
with gr.Blocks(title="LinkedIn Translator") as demo:
|
| 475 |
|
| 476 |
direction_state = gr.State("to_linkedin")
|
| 477 |
|
|
|
|
| 490 |
with gr.Row(equal_height=True):
|
| 491 |
with gr.Column(scale=5):
|
| 492 |
input_box = gr.Textbox(label="βοΈ Normale Aussage",
|
| 493 |
+
placeholder="z.B. 'Ich hab heute meinen Kaffee verschuettet.'",
|
| 494 |
lines=10)
|
| 495 |
with gr.Column(scale=1, min_width=120):
|
| 496 |
gr.HTML("<div style='height:40px'></div>")
|
|
|
|
| 560 |
outputs=[direction_state, input_box, output_box, swap_btn, dir_label, markdown_out, bingo_out],
|
| 561 |
)
|
| 562 |
|
| 563 |
+
demo.launch(css=CSS)
|