Zeggai Abdellah commited on
Commit
ec741a1
·
1 Parent(s): c00327a

fix the paths

Browse files
app.py CHANGED
@@ -140,23 +140,23 @@ def save_dataset_to_space(dataset: Dict, filename: str):
140
  """
141
  Save dataset to a file in the Space's persistent storage
142
  """
143
- persistent_path = f"/home/user/{filename}"
144
  with open(persistent_path, 'w', encoding='utf-8') as f:
145
  json.dump(dataset, f, indent=4, ensure_ascii=False)
146
  print(f"Dataset saved to {persistent_path}")
147
 
148
- # Optionally upload to Space files
149
- try:
150
- api = HfApi(token=os.getenv("HF_TOKEN"))
151
- api.upload_file(
152
- path_or_fileobj=persistent_path,
153
- path_in_repo=filename,
154
- repo_id=os.getenv("SPACE_ID"),
155
- repo_type="space"
156
- )
157
- print(f"File {filename} uploaded to Space")
158
- except Exception as e:
159
- print(f"Could not upload to Space: {e}")
160
 
161
  @app.get("/generate-questions")
162
  async def generate_questions():
@@ -164,19 +164,13 @@ async def generate_questions():
164
  Endpoint to generate questions from the vaccine guide chunks
165
  """
166
  try:
167
- # Try to load chunks from different possible locations
168
- chunks_paths = [
169
- "./Data/Processed_Data/chunks.json",
170
- ]
171
 
172
  chunks_data = None
173
- for path in chunks_paths:
174
- try:
175
- with open(path, "r", encoding="utf-8") as f:
176
- chunks_data = json.load(f)
177
- break
178
- except FileNotFoundError:
179
- continue
180
 
181
  if chunks_data is None:
182
  raise HTTPException(status_code=404, detail="Chunks file not found in any known location")
@@ -202,7 +196,7 @@ async def download_file(filename: str):
202
  """
203
  Endpoint to download generated files
204
  """
205
- file_path = f"/home/user/{filename}"
206
  if os.path.exists(file_path):
207
  return FileResponse(file_path, media_type="application/json", filename=filename)
208
  raise HTTPException(status_code=404, detail="File not found")
 
140
  """
141
  Save dataset to a file in the Space's persistent storage
142
  """
143
+ persistent_path = f"./{filename}"
144
  with open(persistent_path, 'w', encoding='utf-8') as f:
145
  json.dump(dataset, f, indent=4, ensure_ascii=False)
146
  print(f"Dataset saved to {persistent_path}")
147
 
148
+ # # Optionally upload to Space files
149
+ # try:
150
+ # api = HfApi(token=os.getenv("HF_TOKEN"))
151
+ # api.upload_file(
152
+ # path_or_fileobj=persistent_path,
153
+ # path_in_repo=filename,
154
+ # repo_id=os.getenv("SPACE_ID"),
155
+ # repo_type="space"
156
+ # )
157
+ # print(f"File {filename} uploaded to Space")
158
+ # except Exception as e:
159
+ # print(f"Could not upload to Space: {e}")
160
 
161
  @app.get("/generate-questions")
162
  async def generate_questions():
 
164
  Endpoint to generate questions from the vaccine guide chunks
165
  """
166
  try:
 
 
 
 
167
 
168
  chunks_data = None
169
+
170
+
171
+ with open("./chunks.json", "r", encoding="utf-8") as f:
172
+ chunks_data = json.load(f)
173
+
 
 
174
 
175
  if chunks_data is None:
176
  raise HTTPException(status_code=404, detail="Chunks file not found in any known location")
 
196
  """
197
  Endpoint to download generated files
198
  """
199
+ file_path = f".{filename}"
200
  if os.path.exists(file_path):
201
  return FileResponse(file_path, media_type="application/json", filename=filename)
202
  raise HTTPException(status_code=404, detail="File not found")
Data/Processed_Data/chunks.json → chunks.json RENAMED
File without changes