Spaces:
Sleeping
Sleeping
Update gradio_app.py
Browse files- 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
|
81 |
for result in json_results:
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
|
|
84 |
|
85 |
-
# Flatten the JSON
|
86 |
dataframe_results = pd.json_normalize(
|
87 |
json_results,
|
88 |
-
record_path=['claim_objects'],
|
89 |
-
meta=['doc_id', 'details', 'domain'],
|
90 |
-
sep='_',
|
91 |
-
errors='ignore'
|
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
|
115 |
for result in json_results:
|
116 |
-
#
|
117 |
-
|
118 |
-
|
|
|
|
|
|
|
119 |
|
120 |
-
#
|
121 |
-
|
122 |
-
|
|
|
|
|
|
|
123 |
|
124 |
-
#
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
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(
|