gnosticdev commited on
Commit
4b80b16
·
verified ·
1 Parent(s): a3d55f4

Update conver.py

Browse files
Files changed (1) hide show
  1. conver.py +5 -4
conver.py CHANGED
@@ -26,7 +26,6 @@ class URLToAudioConverter:
26
  self.llm_client = OpenAI(api_key=llm_api_key, base_url="https://api.together.xyz/v1")
27
  self.llm_out = None
28
  self._start_cleaner()
29
- # Define audio file paths relative to the script directory
30
  self.ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
31
  self.MUSICA_FONDO = os.path.join(self.ROOT_DIR, "musica.mp3")
32
  self.TAG1 = os.path.join(self.ROOT_DIR, "tag.mp3")
@@ -77,13 +76,15 @@ class URLToAudioConverter:
77
  response_content = response.choices[0].message.content
78
  # Clean response to ensure valid JSON
79
  response_content = response_content.strip()
80
- # Extract valid JSON using regex
81
  json_match = re.search(r'\{.*\}', response_content, re.DOTALL)
82
  if not json_match:
83
  raise ValueError("No valid JSON object found in response")
84
  json_str = json_match.group(0)
85
- # Replace any problematic characters
86
- json_str = json_str.replace('\n', '').replace('\r', '')
 
 
87
  try:
88
  dialogue = json.loads(json_str)
89
  except json.JSONDecodeError as e:
 
26
  self.llm_client = OpenAI(api_key=llm_api_key, base_url="https://api.together.xyz/v1")
27
  self.llm_out = None
28
  self._start_cleaner()
 
29
  self.ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
30
  self.MUSICA_FONDO = os.path.join(self.ROOT_DIR, "musica.mp3")
31
  self.TAG1 = os.path.join(self.ROOT_DIR, "tag.mp3")
 
76
  response_content = response.choices[0].message.content
77
  # Clean response to ensure valid JSON
78
  response_content = response_content.strip()
79
+ # Remove any leading/trailing non-JSON content
80
  json_match = re.search(r'\{.*\}', response_content, re.DOTALL)
81
  if not json_match:
82
  raise ValueError("No valid JSON object found in response")
83
  json_str = json_match.group(0)
84
+ # Replace problematic characters and ensure proper JSON formatting
85
+ json_str = json_str.replace('\n', '').replace('\r', '').replace('\t', '')
86
+ json_str = re.sub(r',\s*}', '}', json_str) # Remove trailing commas
87
+ json_str = re.sub(r',\s*,', ',', json_str) # Remove double commas
88
  try:
89
  dialogue = json.loads(json_str)
90
  except json.JSONDecodeError as e: