thechaiexperiment commited on
Commit
1616205
·
verified ·
1 Parent(s): 24d56f1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -13
app.py CHANGED
@@ -3,7 +3,6 @@ import pickle
3
  import os
4
  import re
5
  import numpy as np
6
- from fastapi.responses import HTMLResponse
7
  import torchvision
8
  import nltk
9
  import torch
@@ -35,7 +34,6 @@ from safetensors.torch import safe_open
35
  nltk.download('punkt_tab')
36
 
37
  app = FastAPI()
38
-
39
  app.add_middleware(
40
  CORSMiddleware,
41
  allow_origins=["*"],
@@ -507,8 +505,6 @@ def translate_en_to_ar(text):
507
  async def root():
508
  return {"message": "Welcome to the FastAPI application! Use the /health endpoint to check health, and /api/query for processing queries."}
509
 
510
-
511
-
512
  @app.get("/health")
513
  async def health_check():
514
  """Health check endpoint"""
@@ -602,8 +598,7 @@ async def resources_endpoint(profile: MedicalProfile):
602
  for i, resource in enumerate(resources):
603
  resource["score"] = scores[i] if i < len(scores) else 0.0
604
  resources.sort(key=lambda x: x["score"], reverse=True)
605
- output = [{"title": resource["title"], "url": resource["url"]} for resource in resources]
606
- print (output)
607
  return output
608
  except ValueError as ve:
609
  raise HTTPException(status_code=400, detail=str(ve))
@@ -632,18 +627,20 @@ async def recipes_endpoint(profile: MedicalProfile):
632
  print("Initial results (document indices and similarities):")
633
  print(initial_results)
634
  document_indices = [doc_id for doc_id, _ in initial_results]
635
- print("Document indices:", document_indices)
636
  metadata_path = 'recipes_metadata.xlsx'
637
  metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
638
  print(f"Retrieved Metadata: {metadata}")
639
  recipes = []
640
- for item in metadata.values():
641
  recipes.append({
642
- "title": item["original_file_name"] if "original_file_name" in item else "Unknown Title",
643
- "url": item["url"] if "url" in item else ""
644
- })
645
- print(recipes)
646
- return recipes
 
 
647
  except ValueError as ve:
648
  raise HTTPException(status_code=400, detail=str(ve))
649
  except Exception as e:
 
3
  import os
4
  import re
5
  import numpy as np
 
6
  import torchvision
7
  import nltk
8
  import torch
 
34
  nltk.download('punkt_tab')
35
 
36
  app = FastAPI()
 
37
  app.add_middleware(
38
  CORSMiddleware,
39
  allow_origins=["*"],
 
505
  async def root():
506
  return {"message": "Welcome to the FastAPI application! Use the /health endpoint to check health, and /api/query for processing queries."}
507
 
 
 
508
  @app.get("/health")
509
  async def health_check():
510
  """Health check endpoint"""
 
598
  for i, resource in enumerate(resources):
599
  resource["score"] = scores[i] if i < len(scores) else 0.0
600
  resources.sort(key=lambda x: x["score"], reverse=True)
601
+ output = [{"title": resource["title"], "url": resource["url"]} for resource in resources]
 
602
  return output
603
  except ValueError as ve:
604
  raise HTTPException(status_code=400, detail=str(ve))
 
627
  print("Initial results (document indices and similarities):")
628
  print(initial_results)
629
  document_indices = [doc_id for doc_id, _ in initial_results]
630
+ print("Document indices:", document_indices)
631
  metadata_path = 'recipes_metadata.xlsx'
632
  metadata = retrieve_metadata(document_indices, metadata_path=metadata_path)
633
  print(f"Retrieved Metadata: {metadata}")
634
  recipes = []
635
+ for item in metadata:
636
  recipes.append({
637
+ "title": item.get("original_file_name", "Unknown Title"),
638
+ "url": item.get("url", "")
639
+ })
640
+ response = {
641
+ "recipes": recipes
642
+ }
643
+ return response
644
  except ValueError as ve:
645
  raise HTTPException(status_code=400, detail=str(ve))
646
  except Exception as e: