Spaces:
Sleeping
Sleeping
Deepak Sahu
commited on
Commit
·
ec6359d
1
Parent(s):
2a28d9d
Update z_generate.py
Browse files- z_generate.py +17 -11
z_generate.py
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
from huggingface_hub import InferenceClient
|
2 |
import os
|
3 |
from typing import List
|
@@ -154,18 +155,23 @@ Question: {question}""".format(context=context, question=query),
|
|
154 |
|
155 |
|
156 |
def parse(value: str) -> List[int]:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
try:
|
158 |
-
#
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
else:
|
166 |
-
print("The input string is not a valid list of numbers.")
|
167 |
-
except Exception as e:
|
168 |
-
print(f"Invalid input string: {value}. Error: {e}")
|
169 |
return []
|
170 |
|
171 |
|
|
|
1 |
+
import ast
|
2 |
from huggingface_hub import InferenceClient
|
3 |
import os
|
4 |
from typing import List
|
|
|
155 |
|
156 |
|
157 |
def parse(value: str) -> List[int]:
|
158 |
+
"""
|
159 |
+
Extracts a list of numbers from the given string.
|
160 |
+
|
161 |
+
Parameters:
|
162 |
+
value (str): The input string containing the list of numbers.
|
163 |
+
|
164 |
+
Returns:
|
165 |
+
list: A list of numbers if found, otherwise an empty list.
|
166 |
+
"""
|
167 |
try:
|
168 |
+
# Find the substring that looks like a list
|
169 |
+
start = value.index('[')
|
170 |
+
end = value.index(']')
|
171 |
+
# Extract and parse it into a Python list
|
172 |
+
return ast.literal_eval(value[start:end+1])
|
173 |
+
except (ValueError, SyntaxError):
|
174 |
+
# Return an empty list if parsing fails
|
|
|
|
|
|
|
|
|
175 |
return []
|
176 |
|
177 |
|