gpaasch commited on
Commit
f9e956a
·
1 Parent(s): ec7356b

should resolve the `ModuleNotFoundError` in the Hugging Face Space while maintaining the local development setup

Browse files
Files changed (3) hide show
  1. app.py +1 -1
  2. src/app.py +1 -1
  3. src/parse_tabular.py +19 -21
app.py CHANGED
@@ -2,4 +2,4 @@
2
  from src.app import demo
3
 
4
  if __name__ == "__main__":
5
- demo.launch(server_name="0.0.0.0", server_port=7860, mcp_server=True)
 
2
  from src.app import demo
3
 
4
  if __name__ == "__main__":
5
+ demo.launch(server_name="0.0.0.0", server_port=7860)
src/app.py CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
5
  from llama_index.core import Settings
6
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
7
  from llama_index.llms.llama_cpp import LlamaCPP
8
- from parse_tabular import create_symptom_index
9
  import json
10
  import psutil
11
  from typing import Tuple, Dict
 
5
  from llama_index.core import Settings
6
  from llama_index.embeddings.huggingface import HuggingFaceEmbedding
7
  from llama_index.llms.llama_cpp import LlamaCPP
8
+ from .parse_tabular import create_symptom_index # Use relative import
9
  import json
10
  import psutil
11
  from typing import Tuple, Dict
src/parse_tabular.py CHANGED
@@ -2,8 +2,8 @@ import xml.etree.ElementTree as ET
2
  import json
3
  import sys
4
  import os
5
- from llama_index.core import VectorStoreIndex, Document, Settings
6
- from llama_index.embeddings.huggingface import HuggingFaceEmbedding
7
 
8
  # Update path constants
9
  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
@@ -53,27 +53,25 @@ def main(xml_path=DEFAULT_XML_PATH):
53
  print(f"Wrote {len(icd_to_description)} code entries to {out_path}")
54
 
55
  def create_symptom_index():
56
- # Configure to use local HuggingFace embeddings
57
- Settings.embed_model = HuggingFaceEmbedding(
58
- model_name="sentence-transformers/all-MiniLM-L6-v2"
59
- )
60
-
61
- # Load and process data
62
- json_path = os.path.join(PROCESSED_DIR, "icd_to_description.json")
63
- with open(json_path, "r") as f:
64
- icd_data = json.load(f)
65
-
66
- # Convert to Document objects
67
- documents = [
68
- Document(
69
- text=f"ICD-10 Code {code}: {desc}",
70
- metadata={"code": code}
71
  )
72
- for code, desc in icd_data.items()
73
- ]
74
 
75
- # Create and return the index
76
- return VectorStoreIndex.from_documents(documents)
 
77
 
78
  # Move this outside the main() function
79
  symptom_index = None
 
2
  import json
3
  import sys
4
  import os
5
+ from llama_index.core import SimpleDirectoryReader, VectorStoreIndex
6
+ from llama_index.core import Settings
7
 
8
  # Update path constants
9
  BASE_DIR = os.path.dirname(os.path.dirname(__file__))
 
53
  print(f"Wrote {len(icd_to_description)} code entries to {out_path}")
54
 
55
  def create_symptom_index():
56
+ """Create and return symptom index from ICD-10 data."""
57
+ try:
58
+ # Load documents from data directory
59
+ documents = SimpleDirectoryReader(
60
+ input_dir="data",
61
+ filename_as_id=True
62
+ ).load_data()
63
+
64
+ # Create vector store index
65
+ index = VectorStoreIndex.from_documents(
66
+ documents,
67
+ show_progress=True
 
 
 
68
  )
69
+
70
+ return index
71
 
72
+ except Exception as e:
73
+ print(f"Error creating symptom index: {e}")
74
+ raise
75
 
76
  # Move this outside the main() function
77
  symptom_index = None