yooi commited on
Commit
eb981be
·
verified ·
1 Parent(s): 4ed5da7

Upload folder using huggingface_hub

Browse files
poetic/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (180 Bytes). View file
 
poetic/__pycache__/card.cpython-312.pyc ADDED
Binary file (4.68 kB). View file
 
poetic/__pycache__/interpretation.cpython-312.pyc ADDED
Binary file (3.53 kB). View file
 
poetic/__pycache__/motion.cpython-312.pyc ADDED
Binary file (732 Bytes). View file
 
poetic/__pycache__/prompts.cpython-312.pyc ADDED
Binary file (1.95 kB). View file
 
poetic/__pycache__/song.cpython-312.pyc ADDED
Binary file (2.69 kB). View file
 
poetic/__pycache__/styles.cpython-312.pyc ADDED
Binary file (5.68 kB). View file
 
poetic/__pycache__/textfree.cpython-312.pyc ADDED
Binary file (943 Bytes). View file
 
poetic/__pycache__/video.cpython-312.pyc ADDED
Binary file (1.83 kB). View file
 
poetic/interpretation.py CHANGED
@@ -16,6 +16,11 @@ def build_interpret_contents(poem: str, correction: str | None = None) -> str:
16
 
17
  _FENCE_RE = re.compile(r"^```[a-zA-Z]*\s*|\s*```$", re.MULTILINE)
18
 
 
 
 
 
 
19
 
20
  def parse_interpretation(text: str) -> Interpretation:
21
  """Parse the model's reply into both audience fields.
@@ -42,6 +47,15 @@ def parse_interpretation(text: str) -> Interpretation:
42
  break
43
  except (json.JSONDecodeError, ValueError):
44
  continue
 
 
 
 
 
 
 
 
 
45
  if obj is None:
46
  raise ValueError(f"Failed to parse interpretation JSON: {text[:120]}")
47
 
 
16
 
17
  _FENCE_RE = re.compile(r"^```[a-zA-Z]*\s*|\s*```$", re.MULTILINE)
18
 
19
+ _FIELDS_RE = re.compile(
20
+ r'"understandingZh"\s*:\s*"(?P<zh>.+?)"\s*,\s*"briefEn"\s*:\s*"(?P<en>.+?)\s*$',
21
+ re.DOTALL,
22
+ )
23
+
24
 
25
  def parse_interpretation(text: str) -> Interpretation:
26
  """Parse the model's reply into both audience fields.
 
47
  break
48
  except (json.JSONDecodeError, ValueError):
49
  continue
50
+ if obj is None:
51
+ # Last resort: generation sometimes stops before the closing brace.
52
+ # Pull the two fields straight out of the (unescaped) fragment.
53
+ match = _FIELDS_RE.search(candidates[-1])
54
+ if match:
55
+ obj = {
56
+ "understandingZh": match.group("zh").strip(),
57
+ "briefEn": match.group("en").strip().rstrip('"}').strip(),
58
+ }
59
  if obj is None:
60
  raise ValueError(f"Failed to parse interpretation JSON: {text[:120]}")
61
 
poetic/providers/__pycache__/__init__.cpython-312.pyc ADDED
Binary file (2.43 kB). View file
 
poetic/providers/__pycache__/hf_api.cpython-312.pyc ADDED
Binary file (7.21 kB). View file
 
poetic/providers/local_zerogpu.py CHANGED
@@ -107,7 +107,7 @@ def _interpret_gpu(poem: str, correction: str | None) -> str:
107
  )
108
  inputs = _tokenizer(prompt_text, return_tensors="pt").to(device)
109
  output = _llm.generate(
110
- **inputs, max_new_tokens=1024, do_sample=True, temperature=0.7, top_p=0.95
111
  )
112
  return _tokenizer.decode(output[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
113
 
 
107
  )
108
  inputs = _tokenizer(prompt_text, return_tensors="pt").to(device)
109
  output = _llm.generate(
110
+ **inputs, max_new_tokens=2048, do_sample=True, temperature=0.7, top_p=0.95
111
  )
112
  return _tokenizer.decode(output[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
113