Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -13,8 +13,12 @@ os.environ["HF_HOME"] = "/app/huggingface"
|
|
13 |
app = FastAPI()
|
14 |
|
15 |
# --- Load Clinical Trials CSV (for metadata lookup) ---
|
16 |
-
csv_path = "
|
17 |
-
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# --- Load FAISS Index ---
|
20 |
dimension = 768
|
@@ -58,12 +62,13 @@ async def retrieve_trial(request: QueryRequest):
|
|
58 |
|
59 |
matched_trials = []
|
60 |
for idx, dist in zip(indices[0], distances[0]):
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
trial_data
|
66 |
-
|
|
|
67 |
|
68 |
return {"matched_trials": matched_trials}
|
69 |
|
|
|
13 |
app = FastAPI()
|
14 |
|
15 |
# --- Load Clinical Trials CSV (for metadata lookup) ---
|
16 |
+
csv_path = "ctg-studies.csv" # Ensure this file is uploaded
|
17 |
+
if os.path.exists(csv_path):
|
18 |
+
df_trials = pd.read_csv(csv_path)
|
19 |
+
print("✅ CSV File Loaded Successfully!")
|
20 |
+
else:
|
21 |
+
raise FileNotFoundError(f"❌ CSV File Not Found: {csv_path}. Upload it first.")
|
22 |
|
23 |
# --- Load FAISS Index ---
|
24 |
dimension = 768
|
|
|
62 |
|
63 |
matched_trials = []
|
64 |
for idx, dist in zip(indices[0], distances[0]):
|
65 |
+
if idx < len(df_trials): # Ensure index is within bounds
|
66 |
+
nct_id = df_trials.iloc[idx]["NCT_ID"] # Get NCT_ID using FAISS index mapping
|
67 |
+
trial_data = get_trial_info(nct_id) # Fetch complete trial details
|
68 |
+
|
69 |
+
if trial_data:
|
70 |
+
trial_data["similarity"] = round(100 / (1 + dist), 2) # Convert similarity
|
71 |
+
matched_trials.append(trial_data)
|
72 |
|
73 |
return {"matched_trials": matched_trials}
|
74 |
|