pvanand commited on
Commit
5aac296
1 Parent(s): 6fe2220

Update helper_functions_api.py

Browse files
Files changed (1) hide show
  1. helper_functions_api.py +10 -11
helper_functions_api.py CHANGED
@@ -103,18 +103,16 @@ def json_from_text(text):
103
  """
104
  Extracts JSON from text using regex and fuzzy JSON loading.
105
  """
106
- match = re.search(r'\{[\s\S]*\}', text)
107
- if match:
108
- json_out = match.group(0)
109
- else:
110
- json_out = text
111
  try:
112
- # Using fuzzy json loader
113
- return loads(json_out)
114
- except Exception:
115
- # Using JSON fixer/ Fixes even half json/ Remove if you need an exception
116
- fix_json = JSONFixer()
117
- return loads(fix_json.fix(json_out).line)
 
 
 
118
 
119
  def remove_stopwords(text):
120
  stop_words = set(stopwords.words('english'))
@@ -143,6 +141,7 @@ def rephrase_content(data_format, content, query):
143
  SysPrompt=SysPromptData,
144
  max_tokens=500,
145
  )
 
146
  class Scraper:
147
  def __init__(self, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"):
148
  self.session = requests.Session()
 
103
  """
104
  Extracts JSON from text using regex and fuzzy JSON loading.
105
  """
 
 
 
 
 
106
  try:
107
+ return json.loads(text)
108
+ except:
109
+ match = re.search(r'\{[\s\S]*\}', text)
110
+ if match:
111
+ json_out = match.group(0)
112
+ else:
113
+ json_out = text
114
+ # Use Fuzzy JSON loading
115
+ return loads(json_out)
116
 
117
  def remove_stopwords(text):
118
  stop_words = set(stopwords.words('english'))
 
141
  SysPrompt=SysPromptData,
142
  max_tokens=500,
143
  )
144
+
145
  class Scraper:
146
  def __init__(self, user_agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"):
147
  self.session = requests.Session()