PanagiotisMark commited on
Commit
3f05e84
·
verified ·
1 Parent(s): 50120bd

Update gradio_app.py

Browse files
Files changed (1) hide show
  1. gradio_app.py +27 -4
gradio_app.py CHANGED
@@ -73,9 +73,16 @@ def news_analysis(text):
73
  headers=HEADERS
74
  )
75
  response.raise_for_status()
 
76
  # Prepare results for JSON output
77
  json_results = response.json()
78
- # Normalize the JSON data
 
 
 
 
 
 
79
  dataframe_results = pd.json_normalize(
80
  json_results,
81
  record_path=['claim_objects'], # Nested array to flatten
@@ -100,14 +107,30 @@ def claim_verification(text):
100
  headers=HEADERS
101
  )
102
  response.raise_for_status()
 
103
  # Prepare results for JSON output
104
  json_results = response.json()
105
- # Normalize the JSON data
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  dataframe_results = pd.json_normalize(
107
  json_results,
108
  record_path=['support', 'refute', 'no_info'], # All possible nested lists
109
- meta=['doc_id', 'details'], # Top-level fields
110
- sep='_', # Custom separator for nested keys
111
  errors='ignore' # To handle cases with missing keys
112
  )
113
  return json_results, dataframe_results
 
73
  headers=HEADERS
74
  )
75
  response.raise_for_status()
76
+
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
 
107
  headers=HEADERS
108
  )
109
  response.raise_for_status()
110
+
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(
130
  json_results,
131
  record_path=['support', 'refute', 'no_info'], # All possible nested lists
132
+ meta=['doc_id', 'details'], # Top-level fields to retain
133
+ sep='_', # Separator for nested fields
134
  errors='ignore' # To handle cases with missing keys
135
  )
136
  return json_results, dataframe_results