GuhanAein commited on
Commit
c8c48f1
·
verified ·
1 Parent(s): b0634d8

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +5 -2
main.py CHANGED
@@ -11,7 +11,10 @@ from huggingface_hub import login
11
 
12
  app = FastAPI()
13
 
14
- # Log in to Hugging Face using environment variable
 
 
 
15
  hf_token = os.getenv("HF_TOKEN")
16
  if not hf_token:
17
  raise ValueError("HF_TOKEN environment variable not set")
@@ -20,7 +23,7 @@ login(hf_token)
20
  # Load Dataset and Prepare Knowledge Base
21
  ds = load_dataset("codeparrot/apps", "all", split="train")
22
  os.makedirs("knowledge_base", exist_ok=True)
23
- for i, example in enumerate(ds.select(range(100))): # Reduced to 100 for free tier
24
  solution = example['solutions'][0] if example['solutions'] else "No solution available"
25
  with open(f"knowledge_base/doc_{i}.txt", "w", encoding="utf-8") as f:
26
  f.write(f"### Problem\n{example['question']}\n\n### Solution\n{solution}")
 
11
 
12
  app = FastAPI()
13
 
14
+ # Set HF_HOME to a writable directory
15
+ os.environ["HF_HOME"] = "/app/.cache"
16
+
17
+ # Log in to Hugging Face
18
  hf_token = os.getenv("HF_TOKEN")
19
  if not hf_token:
20
  raise ValueError("HF_TOKEN environment variable not set")
 
23
  # Load Dataset and Prepare Knowledge Base
24
  ds = load_dataset("codeparrot/apps", "all", split="train")
25
  os.makedirs("knowledge_base", exist_ok=True)
26
+ for i, example in enumerate(ds.select(range(100))):
27
  solution = example['solutions'][0] if example['solutions'] else "No solution available"
28
  with open(f"knowledge_base/doc_{i}.txt", "w", encoding="utf-8") as f:
29
  f.write(f"### Problem\n{example['question']}\n\n### Solution\n{solution}")