quanliang commited on
Commit
85d2660
·
1 Parent(s): eb91cea

Remove unused endpoints and static file mounting from main.py to streamline the application.

Browse files
Files changed (1) hide show
  1. main.py +0 -129
main.py CHANGED
@@ -18,7 +18,6 @@ from rapidfuzz import fuzz
18
  from fastapi import FastAPI, UploadFile, File, Form, BackgroundTasks
19
  from fastapi.responses import JSONResponse, FileResponse
20
  from fastapi.middleware.cors import CORSMiddleware
21
- from fastapi.staticfiles import StaticFiles
22
  from zipfile import ZipFile
23
 
24
  # Setup logging
@@ -357,12 +356,6 @@ app.add_middleware(
357
  allow_headers=["*"]
358
  )
359
 
360
- # Use the directory name for the mount path, not the full path
361
- upload_dir_name = os.path.basename(UPLOAD_DIR)
362
- logger.info(f"Mounting uploaded files at: /{upload_dir_name}")
363
-
364
- app.mount(f"/{upload_dir_name}", StaticFiles(directory=UPLOAD_DIR), name="uploaded")
365
-
366
  # A registry of hash -> filename for each "database" category
367
  FILE_REGISTRY = {}
368
 
@@ -2152,67 +2145,6 @@ async def upload_zip(
2152
  "embedding_started": len(text_pdf_files) > 0 and embedding_model is not None
2153
  })
2154
 
2155
- @app.get("/category_info/{category}")
2156
- async def get_category_info(category: str):
2157
- """
2158
- Get information about the files in a category to determine available modes.
2159
- """
2160
- if category not in FILE_REGISTRY or not FILE_REGISTRY[category]:
2161
- return JSONResponse(content={
2162
- "has_files": False,
2163
- "file_types": {
2164
- "text_pdf_count": 0,
2165
- "image_count": 0,
2166
- "pdf_count": 0,
2167
- "has_images": False,
2168
- "has_text_pdf": False,
2169
- "has_pdfs": False
2170
- },
2171
- "available_modes": []
2172
- })
2173
-
2174
- # Count file types in the category
2175
- text_pdf_count = 0
2176
- image_count = 0
2177
- pdf_count = 0
2178
-
2179
- # Load metadata to check original file types (especially for converted PDFs)
2180
- metadata_dict = load_metadata(category)
2181
-
2182
- for file_hash, filename in FILE_REGISTRY[category].items():
2183
- file_type = get_file_type(filename)
2184
- if file_type == "text_pdf":
2185
- text_pdf_count += 1
2186
- elif file_type == "image":
2187
- image_count += 1
2188
-
2189
- # Check for PDFs using metadata (for converted PDFs) or filename (for direct PDFs)
2190
- if filename.lower().endswith('.pdf'):
2191
- pdf_count += 1
2192
- elif file_hash in metadata_dict:
2193
- original_filename = metadata_dict[file_hash].get('original_filename', '')
2194
- if original_filename.lower().endswith('.pdf'):
2195
- pdf_count += 1
2196
-
2197
- # Determine available modes
2198
- available_modes = []
2199
- if text_pdf_count > 0:
2200
- available_modes.extend(["QA", "System Chart Extraction"])
2201
-
2202
- return JSONResponse(content={
2203
- "has_files": True,
2204
- "file_types": {
2205
- "text_pdf_count": text_pdf_count,
2206
- "image_count": image_count,
2207
- "pdf_count": pdf_count,
2208
- "has_images": image_count > 0,
2209
- "has_text_pdf": text_pdf_count > 0,
2210
- "has_pdfs": pdf_count > 0
2211
- },
2212
- "available_modes": available_modes,
2213
- "total_files": text_pdf_count + image_count
2214
- })
2215
-
2216
  @app.get("/available_databases")
2217
  async def get_available_databases():
2218
  """
@@ -2267,48 +2199,6 @@ async def get_available_databases():
2267
 
2268
  return JSONResponse(content={"databases": databases})
2269
 
2270
- @app.get("/metadata/{database}")
2271
- async def get_database_metadata(database: str):
2272
- """
2273
- Get metadata information for all files in a database.
2274
- Useful for debugging and displaying file information including original PDF titles.
2275
- """
2276
- if database not in FILE_REGISTRY:
2277
- return JSONResponse(content={
2278
- "error": f"Database '{database}' not found"
2279
- }, status_code=404)
2280
-
2281
- metadata = load_metadata(database)
2282
-
2283
- # Combine file registry info with metadata
2284
- files_info = []
2285
- for file_hash, filename in FILE_REGISTRY[database].items():
2286
- file_metadata = metadata.get(file_hash, {})
2287
- file_info = {
2288
- "file_hash": file_hash,
2289
- "file_hash_short": file_hash[:16] + "...",
2290
- "saved_filename": filename,
2291
- "original_filename": file_metadata.get("original_filename", filename),
2292
- "title": file_metadata.get("title", "Unknown"),
2293
- "file_type": file_metadata.get("file_type", "unknown"),
2294
- "upload_timestamp": file_metadata.get("upload_timestamp", "Unknown"),
2295
- "file_size": file_metadata.get("file_size", 0),
2296
- "metadata_found": bool(file_metadata)
2297
- }
2298
- files_info.append(file_info)
2299
-
2300
- return JSONResponse(content={
2301
- "database": database,
2302
- "file_count": len(files_info),
2303
- "files": files_info,
2304
- "metadata_keys": [h[:16] + "..." for h in metadata.keys()],
2305
- "debug": {
2306
- "total_metadata_entries": len(metadata),
2307
- "files_with_metadata": len([f for f in files_info if f["metadata_found"]]),
2308
- "files_without_metadata": len([f for f in files_info if not f["metadata_found"]])
2309
- }
2310
- })
2311
-
2312
  # -------------------- Conversation Management Endpoints -------------------- #
2313
 
2314
  @app.get("/conversations/{extraction_id}")
@@ -2884,25 +2774,6 @@ AI: """
2884
  status_code=500
2885
  )
2886
 
2887
- @app.post("/debug/reload_databases")
2888
- async def reload_databases():
2889
- """
2890
- Debug endpoint to reload databases and trigger metadata migration.
2891
- """
2892
- global FILE_REGISTRY
2893
-
2894
- # Clear current registry
2895
- FILE_REGISTRY = {}
2896
-
2897
- # Reload databases (this will trigger migration)
2898
- load_existing_databases()
2899
-
2900
- return JSONResponse(content={
2901
- "message": "Databases reloaded with metadata migration",
2902
- "databases": list(FILE_REGISTRY.keys()),
2903
- "total_files": sum(len(files) for files in FILE_REGISTRY.values())
2904
- })
2905
-
2906
  def get_admin_password() -> Optional[str]:
2907
  password = os.environ.get("ADMIN_PASSWORD")
2908
  if password:
 
18
  from fastapi import FastAPI, UploadFile, File, Form, BackgroundTasks
19
  from fastapi.responses import JSONResponse, FileResponse
20
  from fastapi.middleware.cors import CORSMiddleware
 
21
  from zipfile import ZipFile
22
 
23
  # Setup logging
 
356
  allow_headers=["*"]
357
  )
358
 
 
 
 
 
 
 
359
  # A registry of hash -> filename for each "database" category
360
  FILE_REGISTRY = {}
361
 
 
2145
  "embedding_started": len(text_pdf_files) > 0 and embedding_model is not None
2146
  })
2147
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2148
  @app.get("/available_databases")
2149
  async def get_available_databases():
2150
  """
 
2199
 
2200
  return JSONResponse(content={"databases": databases})
2201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2202
  # -------------------- Conversation Management Endpoints -------------------- #
2203
 
2204
  @app.get("/conversations/{extraction_id}")
 
2774
  status_code=500
2775
  )
2776
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2777
  def get_admin_password() -> Optional[str]:
2778
  password = os.environ.get("ADMIN_PASSWORD")
2779
  if password: