Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -45,25 +45,35 @@ def get_text_file(docs):
|
|
| 45 |
|
| 46 |
|
| 47 |
def get_csv_file(docs):
|
| 48 |
-
import pandas as pd
|
| 49 |
-
text = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
-
|
| 54 |
-
item_name = row[0]
|
| 55 |
-
row_text = item_name
|
| 56 |
-
for col_name in data.columns[1:]:
|
| 57 |
-
row_text += '{} is {} '.format(col_name, row[col_name])
|
| 58 |
-
text += row_text + '\n'
|
| 59 |
|
| 60 |
-
return text
|
| 61 |
|
| 62 |
def get_json_file(docs):
|
| 63 |
with NamedTemporaryFile() as temp_file:
|
| 64 |
temp_file.write(docs.getvalue())
|
| 65 |
temp_file.seek(0)
|
| 66 |
-
json_loader = JSONLoader(temp_file.name
|
|
|
|
| 67 |
json_doc = json_loader.load()
|
| 68 |
|
| 69 |
return json_doc
|
|
|
|
| 45 |
|
| 46 |
|
| 47 |
def get_csv_file(docs):
|
| 48 |
+
# import pandas as pd
|
| 49 |
+
# text = ''
|
| 50 |
+
|
| 51 |
+
# data = pd.read_csv(docs)
|
| 52 |
+
|
| 53 |
+
# for index, row in data.iterrows():
|
| 54 |
+
# item_name = row[0]
|
| 55 |
+
# row_text = item_name
|
| 56 |
+
# for col_name in data.columns[1:]:
|
| 57 |
+
# row_text += '{} is {} '.format(col_name, row[col_name])
|
| 58 |
+
# text += row_text + '\n'
|
| 59 |
+
|
| 60 |
+
# return text
|
| 61 |
|
| 62 |
+
with NamedTemporaryFile() as temp_file:
|
| 63 |
+
temp_file.write(docs.getvalue())
|
| 64 |
+
temp_file.seek(0)
|
| 65 |
+
text_loader = CSVLoader(temp_file.name)
|
| 66 |
+
text_doc = text_loader.load()
|
| 67 |
|
| 68 |
+
return text_doc
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
|
|
|
| 70 |
|
| 71 |
def get_json_file(docs):
|
| 72 |
with NamedTemporaryFile() as temp_file:
|
| 73 |
temp_file.write(docs.getvalue())
|
| 74 |
temp_file.seek(0)
|
| 75 |
+
json_loader = JSONLoader(temp_file.name,
|
| 76 |
+
jq_schema = '.messages[].content')
|
| 77 |
json_doc = json_loader.load()
|
| 78 |
|
| 79 |
return json_doc
|