1
+ import json
1
2
from io import StringIO
2
- from typing import Tuple
3
+ from typing import Any , Dict , List , Tuple
3
4
4
5
import gradio
5
6
import pandas as pd
@@ -85,7 +86,9 @@ def _load_preview_data(self, selected_view_name: str) -> pd.DataFrame:
85
86
selected_view = self .collection .get (selected_view_name )
86
87
if issubclass (type (selected_view ), BaseStructuredView ):
87
88
selected_view_results = selected_view .execute ()
88
- preview_dataframe = pd .DataFrame .from_records (selected_view_results .results ).head (self .preview_limit )
89
+ preview_dataframe = self ._load_results_into_dataframe (selected_view_results .results ).head (
90
+ self .preview_limit
91
+ )
89
92
else :
90
93
preview_dataframe = pd .DataFrame ()
91
94
@@ -112,7 +115,7 @@ async def _ui_ask_query(
112
115
question = question_query , return_natural_response = natural_language_flag
113
116
)
114
117
generated_query = str (execution_result .context )
115
- data = pd . DataFrame . from_records (execution_result .results )
118
+ data = self . _load_results_into_dataframe (execution_result .results )
116
119
textual_response = str (execution_result .textual_response ) if natural_language_flag else textual_response
117
120
except UnsupportedQueryError :
118
121
generated_query = {"Query" : "unsupported" }
@@ -147,6 +150,19 @@ def _clear_results(self) -> Tuple[gradio.DataFrame, gradio.Label, gradio.Text, g
147
150
gradio .Text (visible = False ),
148
151
)
149
152
153
+ @staticmethod
154
+ def _load_results_into_dataframe (results : List [Dict [str , Any ]]) -> pd .DataFrame :
155
+ """
156
+ Load the results into a pandas DataFrame. Makes sure that the results are json serializable.
157
+
158
+ Args:
159
+ results: The results to load into the DataFrame.
160
+
161
+ Returns:
162
+ The loaded DataFrame.
163
+ """
164
+ return pd .DataFrame (json .loads (json .dumps (results , default = str )))
165
+
150
166
async def create_interface (self , user_collection : Collection , preview_limit : int ) -> gradio .Interface :
151
167
"""
152
168
Creates a Gradio interface for interacting with the user collection and similarity stores.
0 commit comments