Spaces:
Runtime error
Runtime error
Update helper_functions_api.py
Browse files- 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 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
| 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()
|