PanagiotisMark commited on
Commit
988b2a5
·
verified ·
1 Parent(s): 3f05e84

Update gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +31 -18
gradio_app.py CHANGED
@@ -77,18 +77,22 @@ def news_analysis(text):
77
  # Prepare results for JSON output
78
  json_results = response.json()
79
 
80
- # Preprocess to convert the claim_objects from a dict to a list
81
  for result in json_results:
82
- if isinstance(result.get('claim_objects'), dict):
83
- result['claim_objects'] = list(result['claim_objects'].values())
 
 
 
 
84
 
85
- # Flatten the JSON
86
  dataframe_results = pd.json_normalize(
87
  json_results,
88
- record_path=['claim_objects'], # Nested array to flatten
89
- meta=['doc_id', 'details', 'domain'], # Top-level fields to retain
90
- sep='_', # Separator for nested fields
91
- errors='ignore' # To handle cases with missing keys
92
  )
93
  return json_results, dataframe_results
94
  except Exception as e:
@@ -111,19 +115,28 @@ def claim_verification(text):
111
  # Prepare results for JSON output
112
  json_results = response.json()
113
 
114
- # Preprocess to convert nested fields from dict to list
115
  for result in json_results:
116
- # Convert 'support' to a list if it's a dictionary
117
- if isinstance(result.get('support'), dict):
118
- result['support'] = list(result['support'].values())
 
 
 
119
 
120
- # Convert 'refute' to a list if it's a dictionary
121
- if isinstance(result.get('refute'), dict):
122
- result['refute'] = list(result['refute'].values())
 
 
 
123
 
124
- # Convert 'no_info' to a list if it's a dictionary
125
- if isinstance(result.get('no_info'), dict):
126
- result['no_info'] = list(result['no_info'].values())
 
 
 
127
 
128
  # Flatten the JSON
129
  dataframe_results = pd.json_normalize(
 
77
  # Prepare results for JSON output
78
  json_results = response.json()
79
 
80
+ # Preprocess to convert 'claim_objects' from any type to a list
81
  for result in json_results:
82
+ # Ensure 'claim_objects' is a list, or if it's a dict, convert it to a list of its values, else leave it as an empty list
83
+ claim_objects = result.get('claim_objects')
84
+ if isinstance(claim_objects, dict):
85
+ result['claim_objects'] = list(claim_objects.values())
86
+ elif not isinstance(claim_objects, list):
87
+ result['claim_objects'] = [] # Default to empty list if it's not a list or dict
88
 
89
+ # Flatten the JSON for 'claim_objects'
90
  dataframe_results = pd.json_normalize(
91
  json_results,
92
+ record_path=['claim_objects'], # Nested array to flatten
93
+ meta=['doc_id', 'details', 'domain'], # Top-level fields to retain
94
+ sep='_', # Separator for nested fields
95
+ errors='ignore' # To handle cases with missing keys
96
  )
97
  return json_results, dataframe_results
98
  except Exception as e:
 
115
  # Prepare results for JSON output
116
  json_results = response.json()
117
 
118
+ # Preprocess to convert nested fields from any type to lists
119
  for result in json_results:
120
+ # Ensure 'support' is a list, or if it's a dict, convert it to a list of its values, else leave it as an empty list
121
+ support = result.get('support')
122
+ if isinstance(support, dict):
123
+ result['support'] = list(support.values())
124
+ elif not isinstance(support, list):
125
+ result['support'] = [] # Default to empty list if it's not a list or dict
126
 
127
+ # Ensure 'refute' is a list, or if it's a dict, convert it to a list of its values, else leave it as an empty list
128
+ refute = result.get('refute')
129
+ if isinstance(refute, dict):
130
+ result['refute'] = list(refute.values())
131
+ elif not isinstance(refute, list):
132
+ result['refute'] = [] # Default to empty list if it's not a list or dict
133
 
134
+ # Ensure 'no_info' is a list, or if it's a dict, convert it to a list of its values, else leave it as an empty list
135
+ no_info = result.get('no_info')
136
+ if isinstance(no_info, dict):
137
+ result['no_info'] = list(no_info.values())
138
+ elif not isinstance(no_info, list):
139
+ result['no_info'] = [] # Default to empty list if it's not a list or dict
140
 
141
  # Flatten the JSON
142
  dataframe_results = pd.json_normalize(