Spaces:
Sleeping
Sleeping
Update rag.py
Browse files
rag.py
CHANGED
|
@@ -7,7 +7,6 @@ import pandas as pd
|
|
| 7 |
from datasets import load_dataset, Dataset
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
import random
|
| 10 |
-
import glob
|
| 11 |
|
| 12 |
# Load environment variables
|
| 13 |
load_dotenv()
|
|
@@ -37,23 +36,15 @@ UNMATCHED_RESPONSES = [
|
|
| 37 |
"We appreciate your question. It has been forwarded for further processing. Until it’s available here, feel free to visit the official UE website or use the contact options:\n\n📞 +92-42-99262231-33\n✉️ info@ue.edu.pk\n🌐 https://ue.edu.pk"
|
| 38 |
]
|
| 39 |
|
| 40 |
-
# Load
|
| 41 |
-
dataset = []
|
| 42 |
try:
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
if isinstance(data, list):
|
| 48 |
-
for item in data:
|
| 49 |
-
if isinstance(item, dict) and 'Question' in item and 'Answer' in item:
|
| 50 |
-
dataset.append(item)
|
| 51 |
-
else:
|
| 52 |
-
print(f"Invalid entry in {file_path}: {item}")
|
| 53 |
-
else:
|
| 54 |
-
print(f"File {file_path} does not contain a list.")
|
| 55 |
except Exception as e:
|
| 56 |
-
print(f"Error loading
|
|
|
|
| 57 |
|
| 58 |
# Precompute embeddings
|
| 59 |
dataset_questions = [item.get("Question", "").lower().strip() for item in dataset]
|
|
|
|
| 7 |
from datasets import load_dataset, Dataset
|
| 8 |
from dotenv import load_dotenv
|
| 9 |
import random
|
|
|
|
| 10 |
|
| 11 |
# Load environment variables
|
| 12 |
load_dotenv()
|
|
|
|
| 36 |
"We appreciate your question. It has been forwarded for further processing. Until it’s available here, feel free to visit the official UE website or use the contact options:\n\n📞 +92-42-99262231-33\n✉️ info@ue.edu.pk\n🌐 https://ue.edu.pk"
|
| 37 |
]
|
| 38 |
|
| 39 |
+
# Load local dataset
|
|
|
|
| 40 |
try:
|
| 41 |
+
with open('dataset.json', 'r') as f:
|
| 42 |
+
dataset = json.load(f)
|
| 43 |
+
if not all(isinstance(item, dict) and 'Question' in item and 'Answer' in item for item in dataset):
|
| 44 |
+
raise ValueError("Invalid dataset structure")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
except Exception as e:
|
| 46 |
+
print(f"Error loading dataset: {e}")
|
| 47 |
+
dataset = []
|
| 48 |
|
| 49 |
# Precompute embeddings
|
| 50 |
dataset_questions = [item.get("Question", "").lower().strip() for item in dataset]
|