aidn commited on
Commit
f82ec01
·
verified ·
1 Parent(s): de5df9d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
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. Be calibrated: most posts will not score 8-10 on every metric. Reserve 9-10 for truly egregious cases.
74
- - comment is max 5 words in German, dry and precise. NEVER use double quotes (") inside the text. Use single quotes (') instead.
75
- - verdict is one precise sentence in German, max 12 words. Acknowledge substance if present. NEVER use double quotes (") inside the text. Use single quotes (') instead.
 
 
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
- return json.loads(raw)
349
- except Exception:
350
- pass
351
- try:
352
- start = raw.find("{")
353
- end = raw.rfind("}") + 1
354
  if start >= 0 and end > start:
355
- return json.loads(raw[start:end])
 
 
356
  except Exception:
357
  pass
358
- try:
359
- cleaned = " ".join(raw[raw.find("{"):raw.rfind("}")+1].split())
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):