Spaces:
Runtime error
Runtime error
Update agent.py
Browse files
agent.py
CHANGED
@@ -369,17 +369,31 @@ class MyVectorStore:
|
|
369 |
import json
|
370 |
from langchain.schema import Document
|
371 |
|
|
|
|
|
|
|
372 |
# Load the JSON file
|
373 |
-
with open("questions.json", "r", encoding="utf-8") as f:
|
374 |
data = json.load(f)
|
375 |
|
376 |
# Convert each question into a Document
|
377 |
docs = [
|
378 |
Document(
|
379 |
-
page_content=
|
380 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
381 |
)
|
382 |
-
for item in data
|
|
|
383 |
]
|
384 |
|
385 |
|
|
|
369 |
import json
|
370 |
from langchain.schema import Document
|
371 |
|
372 |
+
def reverse_text(text: str) -> str:
|
373 |
+
return text[::-1].replace("\\", "") # Handle escaped quotes
|
374 |
+
|
375 |
# Load the JSON file
|
376 |
+
with open("https://huggingface.co/spaces/wt002/Final_Assignment_Project/blob/main/questions.json", "r", encoding="utf-8") as f:
|
377 |
data = json.load(f)
|
378 |
|
379 |
# Convert each question into a Document
|
380 |
docs = [
|
381 |
Document(
|
382 |
+
page_content=(
|
383 |
+
str(reverse_text(item["question"]))
|
384 |
+
if isinstance(item["question"], (list, bytes))
|
385 |
+
else reverse_text(item["question"])
|
386 |
+
if item["question"].startswith(('.', ','))
|
387 |
+
else item["question"]
|
388 |
+
),
|
389 |
+
metadata={
|
390 |
+
"task_id": item["task_id"],
|
391 |
+
"level": item["Level"],
|
392 |
+
"file_name": item["file_name"] # Added from your URL example
|
393 |
+
}
|
394 |
)
|
395 |
+
for item in data
|
396 |
+
if "question" in item and item["question"] # Skip empty questions
|
397 |
]
|
398 |
|
399 |
|