Kevin Wu commited on
Commit
2fbeb10
1 Parent(s): 0e0266f
Files changed (1) hide show
  1. app.py +4 -15
app.py CHANGED
@@ -33,19 +33,16 @@ def parse_xml_response(xml_string: str) -> pd.DataFrame:
33
  """
34
  try:
35
  # Extract only the XML content between the outermost tags
36
- xml_content = re.search(r'<[^>]+>.*</[^>]+>', xml_string, re.DOTALL)
37
- if xml_content:
38
- xml_string = xml_content.group(0)
39
- else:
40
  print("No valid XML content found.")
41
  return pd.DataFrame()
42
 
43
  # Wrap the content in a root element to ensure there's only one root
44
- xml_string = f"<root>{xml_string}</root>"
45
 
46
  # Parse the XML
47
- parser = ET.XMLParser(recover=True) # This allows for more lenient parsing
48
- root = ET.fromstring(xml_string, parser=parser)
49
 
50
  result = {}
51
 
@@ -167,14 +164,6 @@ def process(file_content):
167
  response = get_response(message_file.id, demo.id) # This now includes retry logic
168
  df = parse_xml_response(response)
169
 
170
- # ... (rest of the function remains the same)
171
-
172
- except Exception as e:
173
- error_message = f"An error occurred while processing the file: {str(e)}"
174
- print(error_message)
175
- print(f"Traceback: {traceback.format_exc()}")
176
- return f"<p>{error_message}</p>"
177
-
178
  if df.empty:
179
  return "<p>No valid information could be extracted from the provided file.</p>"
180
 
 
33
  """
34
  try:
35
  # Extract only the XML content between the outermost tags
36
+ xml_content = re.findall(r'<[^>]+>.*?</[^>]+>', xml_string, re.DOTALL)
37
+ if not xml_content:
 
 
38
  print("No valid XML content found.")
39
  return pd.DataFrame()
40
 
41
  # Wrap the content in a root element to ensure there's only one root
42
+ xml_string = f"<root>{''.join(xml_content)}</root>"
43
 
44
  # Parse the XML
45
+ root = ET.fromstring(xml_string)
 
46
 
47
  result = {}
48
 
 
164
  response = get_response(message_file.id, demo.id) # This now includes retry logic
165
  df = parse_xml_response(response)
166
 
 
 
 
 
 
 
 
 
167
  if df.empty:
168
  return "<p>No valid information could be extracted from the provided file.</p>"
169