xangma commited on
Commit
55da24c
β€’
1 Parent(s): 802665c

big fix. Wow it was broken.

Browse files
Files changed (2) hide show
  1. app.py +22 -21
  2. ingest.py +9 -8
app.py CHANGED
@@ -60,7 +60,7 @@ def set_chain_up(openai_api_key, model_selector, k_textbox, max_tokens_textbox,
60
  else:
61
  return agent
62
 
63
- def delete_vs(all_collections_state, collections_viewer):
64
  client = chromadb.Client(Settings(
65
  chroma_db_impl="duckdb+parquet",
66
  persist_directory=".persisted_data" # Optional, defaults to .chromadb/ in the current directory
@@ -68,9 +68,10 @@ def delete_vs(all_collections_state, collections_viewer):
68
  for collection in collections_viewer:
69
  client.delete_collection(collection)
70
  all_collections_state.remove(collection)
71
- return all_collections_state
 
72
 
73
- def delete_all_vs(all_collections_state):
74
  shutil.rmtree(".persisted_data")
75
  return []
76
 
@@ -105,14 +106,14 @@ def chat(inp, history, agent):
105
  if agent == 'all_vs_deleted':
106
  history.append((inp, "All vectorstores deleted"))
107
  return history, history
108
-
109
- print("\n==== date/time: " + str(datetime.datetime.now()) + " ====")
110
- print("inp: " + inp)
111
- history = history or []
112
- output = agent({"question": inp, "chat_history": history})
113
- answer = output["answer"]
114
- history.append((inp, answer))
115
- print(history)
116
  return history, history
117
 
118
  block = gr.Blocks(css=".gradio-container {background-color: system;}")
@@ -170,14 +171,14 @@ with block:
170
  with gr.Row():
171
  with gr.Column(scale=2):
172
  all_collections_to_get = gr.List(headers=['New Collections to make'],row_count=3, label='Collections_to_get', show_label=True, interactive=True, max_cols=1, max_rows=3)
173
- make_vs_button = gr.Button(value="Make new collection(s)", variant="secondary").style(full_width=False)
174
  with gr.Column(scale=2):
175
  collections_viewer = gr.CheckboxGroup(choices=[], label='Collections_viewer', show_label=True)
176
  with gr.Column(scale=1):
177
- get_vs_button = gr.Button(value="Load collection(s) to chat!", variant="secondary").style(full_width=False)
178
- get_all_vs_names_button = gr.Button(value="List all saved collections", variant="secondary").style(full_width=False)
179
- delete_vs_button = gr.Button(value="Delete selected saved collections", variant="secondary").style(full_width=False)
180
- delete_all_vs_button = gr.Button(value="Delete all saved collections", variant="secondary").style(full_width=False)
181
  gr.HTML(
182
  "<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain πŸ¦œοΈπŸ”—</a></center>"
183
  )
@@ -191,11 +192,11 @@ with block:
191
  submit.click(set_chain_up, inputs=[openai_api_key_textbox, model_selector, k_textbox, max_tokens_textbox, vs_state, agent_state], outputs=[agent_state])
192
  message.submit(chat, inputs=[message, history_state, agent_state], outputs=[chatbot, history_state])
193
 
194
- get_vs_button.click(merge_collections, inputs=[collections_viewer, vs_state], outputs=[vs_state])#.then(set_chain_up, inputs=[openai_api_key_textbox, model_selector, k_textbox, max_tokens_textbox, vs_state, agent_state], outputs=[agent_state])
195
- make_vs_button.click(ingest_docs, inputs=[all_collections_state, all_collections_to_get], outputs=[all_collections_state], show_progress=True).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
196
- delete_vs_button.click(delete_vs, inputs=[all_collections_state, collections_viewer], outputs=[all_collections_state]).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
197
- delete_all_vs_button.click(delete_all_vs, inputs=[all_collections_state], outputs=[all_collections_state]).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
198
- get_all_vs_names_button.click(list_collections, inputs=[all_collections_state], outputs=[all_collections_state]).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
199
 
200
  # Whenever chain parameters change, destroy the agent.
201
  input_list = [openai_api_key_textbox, model_selector, k_textbox, max_tokens_textbox]
 
60
  else:
61
  return agent
62
 
63
+ def delete_collection(all_collections_state, collections_viewer):
64
  client = chromadb.Client(Settings(
65
  chroma_db_impl="duckdb+parquet",
66
  persist_directory=".persisted_data" # Optional, defaults to .chromadb/ in the current directory
 
68
  for collection in collections_viewer:
69
  client.delete_collection(collection)
70
  all_collections_state.remove(collection)
71
+ collections_viewer.remove(collection)
72
+ return all_collections_state, collections_viewer
73
 
74
+ def delete_all_collections(all_collections_state):
75
  shutil.rmtree(".persisted_data")
76
  return []
77
 
 
106
  if agent == 'all_vs_deleted':
107
  history.append((inp, "All vectorstores deleted"))
108
  return history, history
109
+ else:
110
+ print("\n==== date/time: " + str(datetime.datetime.now()) + " ====")
111
+ print("inp: " + inp)
112
+ history = history or []
113
+ output = agent({"question": inp, "chat_history": history})
114
+ answer = output["answer"]
115
+ history.append((inp, answer))
116
+ print(history)
117
  return history, history
118
 
119
  block = gr.Blocks(css=".gradio-container {background-color: system;}")
 
171
  with gr.Row():
172
  with gr.Column(scale=2):
173
  all_collections_to_get = gr.List(headers=['New Collections to make'],row_count=3, label='Collections_to_get', show_label=True, interactive=True, max_cols=1, max_rows=3)
174
+ make_collections_button = gr.Button(value="Make new collection(s)", variant="secondary").style(full_width=False)
175
  with gr.Column(scale=2):
176
  collections_viewer = gr.CheckboxGroup(choices=[], label='Collections_viewer', show_label=True)
177
  with gr.Column(scale=1):
178
+ load_collections_button = gr.Button(value="Load collection(s) to chat!", variant="secondary").style(full_width=False)
179
+ get_all_collection_names_button = gr.Button(value="List all saved collections", variant="secondary").style(full_width=False)
180
+ delete_collections_button = gr.Button(value="Delete selected saved collections", variant="secondary").style(full_width=False)
181
+ delete_all_collections_button = gr.Button(value="Delete all saved collections", variant="secondary").style(full_width=False)
182
  gr.HTML(
183
  "<center>Powered by <a href='https://github.com/hwchase17/langchain'>LangChain πŸ¦œοΈπŸ”—</a></center>"
184
  )
 
192
  submit.click(set_chain_up, inputs=[openai_api_key_textbox, model_selector, k_textbox, max_tokens_textbox, vs_state, agent_state], outputs=[agent_state])
193
  message.submit(chat, inputs=[message, history_state, agent_state], outputs=[chatbot, history_state])
194
 
195
+ load_collections_button.click(merge_collections, inputs=[collections_viewer, vs_state], outputs=[vs_state])#.then(set_chain_up, inputs=[openai_api_key_textbox, model_selector, k_textbox, max_tokens_textbox, vs_state, agent_state], outputs=[agent_state])
196
+ make_collections_button.click(ingest_docs, inputs=[all_collections_state, all_collections_to_get], outputs=[all_collections_state], show_progress=True).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
197
+ delete_collections_button.click(delete_collection, inputs=[all_collections_state, collections_viewer], outputs=[all_collections_state, collections_viewer]).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
198
+ delete_all_collections_button.click(delete_all_collections, inputs=[all_collections_state], outputs=[all_collections_state]).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
199
+ get_all_collection_names_button.click(list_collections, inputs=[all_collections_state], outputs=[all_collections_state]).then(update_checkboxgroup, inputs = [all_collections_state], outputs = [collections_viewer])
200
 
201
  # Whenever chain parameters change, destroy the agent.
202
  input_list = [openai_api_key_textbox, model_selector, k_textbox, max_tokens_textbox]
ingest.py CHANGED
@@ -95,7 +95,7 @@ def ingest_docs(all_collections_state, urls):
95
  else:
96
  folder = '.'
97
  else:
98
- destination = Path('downloaded/'+url)
99
  destination.mkdir(exist_ok=True, parents=True)
100
  destination = destination.as_posix()
101
  if url[0] == '/':
@@ -136,14 +136,15 @@ def ingest_docs(all_collections_state, urls):
136
  file_path = os.path.join(root, file)
137
  rel_file_path = os.path.relpath(file_path, local_repo_path_1)
138
  ext = rel_file_path.split('.')[-1]
 
 
139
  try:
140
- if '.' not in [i[0] for i in rel_file_path.split('/')]:
141
- if paths_by_ext.get(rel_file_path.split('.')[-1]) is None:
142
- paths_by_ext["other"].append(rel_file_path)
143
- docs_by_ext["other"].append(TextLoader(os.path.join(local_repo_path_1, rel_file_path)).load()[0])
144
- else:
145
- paths_by_ext[ext].append(rel_file_path)
146
- docs_by_ext[ext].append(TextLoader(os.path.join(local_repo_path_1, rel_file_path)).load()[0])
147
  except Exception as e:
148
  continue
149
  for ext in docs_by_ext.keys():
 
95
  else:
96
  folder = '.'
97
  else:
98
+ destination = os.path.join('downloaded',url)
99
  destination.mkdir(exist_ok=True, parents=True)
100
  destination = destination.as_posix()
101
  if url[0] == '/':
 
136
  file_path = os.path.join(root, file)
137
  rel_file_path = os.path.relpath(file_path, local_repo_path_1)
138
  ext = rel_file_path.split('.')[-1]
139
+ if rel_file_path.startswith('.'):
140
+ continue
141
  try:
142
+ if paths_by_ext.get(rel_file_path.split('.')[-1]) is None:
143
+ paths_by_ext["other"].append(rel_file_path)
144
+ docs_by_ext["other"].append(TextLoader(os.path.join(local_repo_path_1, rel_file_path)).load()[0])
145
+ else:
146
+ paths_by_ext[ext].append(rel_file_path)
147
+ docs_by_ext[ext].append(TextLoader(os.path.join(local_repo_path_1, rel_file_path)).load()[0])
 
148
  except Exception as e:
149
  continue
150
  for ext in docs_by_ext.keys():