Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,16 +5,21 @@ import markdown
|
|
5 |
|
6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
7 |
|
8 |
-
# Function to read and process Markdown files from the 'data' directory
|
9 |
def load_markdown_files(data_folder='data'):
|
10 |
documents = []
|
11 |
-
for
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
18 |
return documents
|
19 |
|
20 |
# Load documents at startup
|
@@ -62,7 +67,7 @@ def retrieve_relevant_context(query, documents):
|
|
62 |
relevant_contexts = []
|
63 |
|
64 |
for doc in documents:
|
65 |
-
if query.lower() in doc.lower(): # Basic keyword search
|
66 |
relevant_contexts.append(doc)
|
67 |
|
68 |
return relevant_contexts[:3] # Return top 3 relevant contexts
|
|
|
5 |
|
6 |
client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
|
7 |
|
8 |
+
# Function to read and process Markdown files from the 'data' directory and its subfolders
|
9 |
def load_markdown_files(data_folder='data'):
|
10 |
documents = []
|
11 |
+
for root, dirs, files in os.walk(data_folder):
|
12 |
+
for filename in files:
|
13 |
+
if filename.endswith('.md'):
|
14 |
+
file_path = os.path.join(root, filename)
|
15 |
+
try:
|
16 |
+
with open(file_path, 'r', encoding='utf-8') as file:
|
17 |
+
content = file.read()
|
18 |
+
# Convert Markdown to plain text if needed
|
19 |
+
html_content = markdown.markdown(content)
|
20 |
+
documents.append(html_content) # Store HTML content or plain text
|
21 |
+
except Exception as e:
|
22 |
+
print(f"Error reading {file_path}: {e}")
|
23 |
return documents
|
24 |
|
25 |
# Load documents at startup
|
|
|
67 |
relevant_contexts = []
|
68 |
|
69 |
for doc in documents:
|
70 |
+
if query.lower() in doc.lower(): # Basic keyword search
|
71 |
relevant_contexts.append(doc)
|
72 |
|
73 |
return relevant_contexts[:3] # Return top 3 relevant contexts
|