Spaces:
Runtime error
Runtime error
Update helpers.py
Browse files- helpers.py +11 -4
helpers.py
CHANGED
@@ -148,12 +148,19 @@ key = os.getenv("GOOGLE_API_KEY")
|
|
148 |
|
149 |
def extract_metadata(response):
|
150 |
if not isinstance(response, str):
|
151 |
-
response = str(response) # Chuyển
|
152 |
|
153 |
-
# Tìm
|
154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
155 |
if not matches:
|
156 |
-
return None #
|
157 |
|
158 |
smallest_dict = None
|
159 |
min_length = float("inf")
|
|
|
148 |
|
149 |
def extract_metadata(response):
|
150 |
if not isinstance(response, str):
|
151 |
+
response = str(response) # Chuyển về string nếu cần
|
152 |
|
153 |
+
# Tìm phần "text" trước
|
154 |
+
text_match = re.search(r'"text":\s*"([^"]+)"', response, re.DOTALL)
|
155 |
+
if not text_match:
|
156 |
+
return None # Không tìm thấy phần text nào
|
157 |
+
|
158 |
+
text_content = text_match.group(1) # Lấy nội dung trong "text"
|
159 |
+
|
160 |
+
# Tìm tất cả dictionary trong text_content
|
161 |
+
matches = re.findall(r'\{.*?\}', text_content, re.DOTALL)
|
162 |
if not matches:
|
163 |
+
return None # Không tìm thấy dict nào
|
164 |
|
165 |
smallest_dict = None
|
166 |
min_length = float("inf")
|