ecyht2 commited on
Commit
71d9c83
·
verified ·
1 Parent(s): 0aa50d3

feat: Added support for subdirectories

Browse files
Files changed (1) hide show
  1. app.py +15 -15
app.py CHANGED
@@ -107,23 +107,23 @@ def predict(query, max_characters) -> str:
107
  return relevant_chunks
108
 
109
 
110
-
111
  docs = {}
112
 
113
- for filename in glob.glob("sources/*"):
114
- if filename.endswith("add_your_files_here"):
115
- continue
116
-
117
- converted_doc = convert(filename)
118
-
119
- chunks = chunk_to_length(converted_doc, chunk_size)
120
- embeddings = model.encode(chunks)
121
-
122
- docs[filename] = {
123
- "chunks": chunks,
124
- "embeddings": embeddings,
125
- }
126
-
 
127
 
128
  gr.Interface(
129
  predict,
 
107
  return relevant_chunks
108
 
109
 
 
110
  docs = {}
111
 
112
+ for root, _, files in os.walk("sources"):
113
+ for filename in files:
114
+ filename = os.path.join(root, filename)
115
+ if filename.endswith("add_your_files_here"):
116
+ continue
117
+
118
+ converted_doc = convert(filename)
119
+
120
+ chunks = chunk_to_length(converted_doc, chunk_size)
121
+ embeddings = model.encode(chunks)
122
+
123
+ docs[filename] = {
124
+ "chunks": chunks,
125
+ "embeddings": embeddings,
126
+ }
127
 
128
  gr.Interface(
129
  predict,