Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -53,7 +53,7 @@ def get_json_file(json_docs):
|
|
53 |
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
54 |
with open(temp_filepath, "wb") as f:
|
55 |
f.write(json_docs.getvalue())
|
56 |
-
json_loader = JSONLoader(temp_filepath, jq_schema='.messages[]', content_key="content")
|
57 |
json_doc = json_loader.load()
|
58 |
return json_doc
|
59 |
|
@@ -111,6 +111,18 @@ def handle_userinput(user_question):
|
|
111 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
112 |
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
def main():
|
115 |
load_dotenv()
|
116 |
st.set_page_config(page_title="Chat with multiple Files",
|
|
|
53 |
temp_filepath = os.path.join(temp_dir.name, json_docs.name)
|
54 |
with open(temp_filepath, "wb") as f:
|
55 |
f.write(json_docs.getvalue())
|
56 |
+
json_loader = JSONLoader(temp_filepath, jq_schema='.messages[]', content_key="content", metadata_func=metadata_func)
|
57 |
json_doc = json_loader.load()
|
58 |
return json_doc
|
59 |
|
|
|
111 |
"{{MSG}}", message.content), unsafe_allow_html=True)
|
112 |
|
113 |
|
114 |
+
def metadata_func(record: dict, metadata: dict) -> dict:
|
115 |
+
|
116 |
+
metadata["sender_name"] = record.get("sender_name")
|
117 |
+
metadata["timestamp_ms"] = record.get("timestamp_ms")
|
118 |
+
|
119 |
+
if "source" in metadata:
|
120 |
+
source = metadata["source"].split("/")
|
121 |
+
source = source[source.index("langchain"):]
|
122 |
+
metadata["source"] = "/".join(source)
|
123 |
+
|
124 |
+
return metadata
|
125 |
+
|
126 |
def main():
|
127 |
load_dotenv()
|
128 |
st.set_page_config(page_title="Chat with multiple Files",
|