Spaces:
Sleeping
Sleeping
Update agent.py
Browse files
agent.py
CHANGED
|
@@ -392,17 +392,27 @@ class MyVectorStore:
|
|
| 392 |
# Prepare Documents
|
| 393 |
# -----------------------------
|
| 394 |
# Define the URL where the JSON file is hosted
|
| 395 |
-
url = "https://huggingface.co/spaces/wt002/Final_Assignment_Project/blob/main/questions.json"
|
| 396 |
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
| 398 |
response = requests.get(url)
|
| 399 |
-
response.raise_for_status() # Ensure that the request was successful
|
| 400 |
|
| 401 |
-
#
|
| 402 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 403 |
|
| 404 |
-
# Assuming the JSON structure has a 'text' field for each document
|
| 405 |
-
texts = [doc.get('text', '') for doc in docs if 'text' in doc] # Extract text from JSON
|
| 406 |
|
| 407 |
# Initialize the embedding model
|
| 408 |
embedding_model = BERTEmbeddings()
|
|
|
|
| 392 |
# Prepare Documents
|
| 393 |
# -----------------------------
|
| 394 |
# Define the URL where the JSON file is hosted
|
|
|
|
| 395 |
|
| 396 |
+
import requests
|
| 397 |
+
import json
|
| 398 |
+
|
| 399 |
+
url = "https://huggingface.co/spaces/wt002/Final_Assignment_Project/blob/main/questions.json"
|
| 400 |
response = requests.get(url)
|
|
|
|
| 401 |
|
| 402 |
+
# Check status
|
| 403 |
+
if response.status_code != 200:
|
| 404 |
+
raise ValueError(f"Failed to fetch data: {response.status_code}")
|
| 405 |
+
|
| 406 |
+
# Parse JSON content
|
| 407 |
+
try:
|
| 408 |
+
docs = response.json() # or json.loads(response.text)
|
| 409 |
+
except json.JSONDecodeError as e:
|
| 410 |
+
print("Response was:", response.text)
|
| 411 |
+
raise e
|
| 412 |
+
|
| 413 |
+
# Extract text
|
| 414 |
+
texts = [doc.get("text", "") for doc in docs if isinstance(doc, dict)]
|
| 415 |
|
|
|
|
|
|
|
| 416 |
|
| 417 |
# Initialize the embedding model
|
| 418 |
embedding_model = BERTEmbeddings()
|