Spaces:
Sleeping
Sleeping
update app
Browse files
app.py
CHANGED
@@ -318,6 +318,29 @@ class ModeloDataset:
|
|
318 |
def unir_columna_valores(self,df,columna):
|
319 |
out = ','.join(df[columna])
|
320 |
return out
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
321 |
modelo = ModeloDataset()
|
322 |
model = Model()
|
323 |
def get_model():
|
@@ -343,8 +366,10 @@ def procesar(texto,archivo):
|
|
343 |
#return "", df_new, df_new.to_excel( index=False)
|
344 |
else:
|
345 |
if archivo.name.split(".")[1]=="json":
|
346 |
-
|
347 |
-
|
|
|
|
|
348 |
demo = gr.Interface(fn=procesar,inputs=["text",gr.File()] , outputs=["text",gr.Dataframe(interactive=False),"text"])
|
349 |
#
|
350 |
demo.launch(share=True)
|
|
|
318 |
def unir_columna_valores(self,df,columna):
|
319 |
out = ','.join(df[columna])
|
320 |
return out
|
321 |
+
class utilJSON:
|
322 |
+
def __init__(self,archivo):
|
323 |
+
with open(archivo, encoding='utf-8') as f:
|
324 |
+
self.data = json.load(f)
|
325 |
+
def obtener_keys_json(self,data):
|
326 |
+
out=[]
|
327 |
+
for key in data:
|
328 |
+
out.append(key)
|
329 |
+
return(out)
|
330 |
+
|
331 |
+
def obtener_dataframe(self,data):
|
332 |
+
claves=self.obtener_keys_json(data)
|
333 |
+
if len(claves)==1:
|
334 |
+
df = pd.json_normalize(
|
335 |
+
data=data[claves[0]],
|
336 |
+
#meta=['title', 'author'],
|
337 |
+
#record_path='reviews',
|
338 |
+
#errors='raise'
|
339 |
+
)
|
340 |
+
else:
|
341 |
+
df = pd.json_normalize(data)
|
342 |
+
|
343 |
+
return df
|
344 |
modelo = ModeloDataset()
|
345 |
model = Model()
|
346 |
def get_model():
|
|
|
366 |
#return "", df_new, df_new.to_excel( index=False)
|
367 |
else:
|
368 |
if archivo.name.split(".")[1]=="json":
|
369 |
+
util = utilJSON("books.json")
|
370 |
+
df=util.obtener_dataframe(util.data)
|
371 |
+
return "", df, df.to_csv(sep='\t', encoding='utf-8',index=False)
|
372 |
+
|
373 |
demo = gr.Interface(fn=procesar,inputs=["text",gr.File()] , outputs=["text",gr.Dataframe(interactive=False),"text"])
|
374 |
#
|
375 |
demo.launch(share=True)
|