Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import os
|
|
|
|
| 2 |
import json
|
| 3 |
import datetime
|
| 4 |
import tempfile
|
|
@@ -70,9 +71,11 @@ Use exactly this structure:
|
|
| 70 |
{"metrics":[{"label":"Buzzword-Dichte","score":3,"comment":"kurz sarkastisch"},{"label":"Länge vs. Inhalt","score":4,"comment":"kurz sarkastisch"},{"label":"Selbstbeweihräuche","score":2,"comment":"kurz sarkastisch"},{"label":"Hashtag-Overload","score":5,"comment":"kurz sarkastisch"},{"label":"Sinnlosigkeits-Index","score":3,"comment":"kurz sarkastisch"}],"verdict":"Ein präzises Urteil auf Deutsch."}
|
| 71 |
|
| 72 |
Rules:
|
| 73 |
-
- score is an integer 1-10.
|
| 74 |
-
- comment is max 5 words in German, dry and precise.
|
| 75 |
-
- verdict is one precise sentence in German, max 12 words.
|
|
|
|
|
|
|
| 76 |
- ALL string values must be valid JSON strings."""
|
| 77 |
|
| 78 |
PROMPT_AI_TUNING = """You are a top-tier Ghostwriter for Tech Executives and a master of LinkedIn algorithms. Your task is to rewrite the provided text into a high-performing LinkedIn post based STRICTLY on the tuning parameters.
|
|
@@ -344,23 +347,20 @@ def translate(text, direction):
|
|
| 344 |
|
| 345 |
|
| 346 |
def _extract_json(raw):
|
|
|
|
|
|
|
|
|
|
| 347 |
try:
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
pass
|
| 351 |
-
try:
|
| 352 |
-
start = raw.find("{")
|
| 353 |
-
end = raw.rfind("}") + 1
|
| 354 |
if start >= 0 and end > start:
|
| 355 |
-
|
|
|
|
|
|
|
| 356 |
except Exception:
|
| 357 |
pass
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
return json.loads(cleaned)
|
| 361 |
-
except Exception:
|
| 362 |
-
pass
|
| 363 |
-
raise ValueError("Kein valides JSON gefunden")
|
| 364 |
|
| 365 |
|
| 366 |
def get_bingo(text):
|
|
|
|
| 1 |
import os
|
| 2 |
+
import re
|
| 3 |
import json
|
| 4 |
import datetime
|
| 5 |
import tempfile
|
|
|
|
| 71 |
{"metrics":[{"label":"Buzzword-Dichte","score":3,"comment":"kurz sarkastisch"},{"label":"Länge vs. Inhalt","score":4,"comment":"kurz sarkastisch"},{"label":"Selbstbeweihräuche","score":2,"comment":"kurz sarkastisch"},{"label":"Hashtag-Overload","score":5,"comment":"kurz sarkastisch"},{"label":"Sinnlosigkeits-Index","score":3,"comment":"kurz sarkastisch"}],"verdict":"Ein präzises Urteil auf Deutsch."}
|
| 72 |
|
| 73 |
Rules:
|
| 74 |
+
- score is an integer 1-10.
|
| 75 |
+
- comment is max 5 words in German, dry and precise.
|
| 76 |
+
- verdict is one precise sentence in German, max 12 words.
|
| 77 |
+
- CRITICAL JSON RULE: NEVER quote parts of the user's text (no hashtags, no phrases). Paraphrase instead.
|
| 78 |
+
- CRITICAL JSON RULE: NEVER use the double-quote character (") inside your string values! Use single quotes (') if you must.
|
| 79 |
- ALL string values must be valid JSON strings."""
|
| 80 |
|
| 81 |
PROMPT_AI_TUNING = """You are a top-tier Ghostwriter for Tech Executives and a master of LinkedIn algorithms. Your task is to rewrite the provided text into a high-performing LinkedIn post based STRICTLY on the tuning parameters.
|
|
|
|
| 347 |
|
| 348 |
|
| 349 |
def _extract_json(raw):
|
| 350 |
+
cleaned_raw = re.sub(r'```json\s*', '', raw)
|
| 351 |
+
cleaned_raw = re.sub(r'```\s*', '', cleaned_raw)
|
| 352 |
+
|
| 353 |
try:
|
| 354 |
+
start = cleaned_raw.find("{")
|
| 355 |
+
end = cleaned_raw.rfind("}") + 1
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
if start >= 0 and end > start:
|
| 357 |
+
json_str = cleaned_raw[start:end]
|
| 358 |
+
json_str = json_str.replace('\n', ' ').replace('\r', '')
|
| 359 |
+
return json.loads(json_str)
|
| 360 |
except Exception:
|
| 361 |
pass
|
| 362 |
+
|
| 363 |
+
raise ValueError(f"Kein valides JSON gefunden. Raw Output war: {raw[:100]}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
|
| 365 |
|
| 366 |
def get_bingo(text):
|