DonImages commited on
Commit
5dbbf26
·
verified ·
1 Parent(s): 37f9623

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -2
app.py CHANGED
@@ -1,14 +1,24 @@
1
  from fastapi import FastAPI, HTTPException
 
2
  import base64
3
  import os
4
 
5
  app = FastAPI()
6
 
7
- # Load LoRA weights on startup
 
 
 
 
 
 
 
 
 
8
  lora_weights = None
9
 
10
  @app.on_event("startup")
11
- def load_lora_weights():
12
  global lora_weights
13
  lora_path = "./lora_file.pth"
14
  if os.path.exists(lora_path):
@@ -17,6 +27,7 @@ def load_lora_weights():
17
  lora_weights = base64.b64encode(f.read()).decode("utf-8")
18
  print("LoRA weights loaded and preprocessed successfully.")
19
  else:
 
20
  raise HTTPException(status_code=500, detail="LoRA file not found.")
21
 
22
  @app.post("/modify-prompt")
 
1
  from fastapi import FastAPI, HTTPException
2
+ from fastapi.middleware.cors import CORSMiddleware
3
  import base64
4
  import os
5
 
6
  app = FastAPI()
7
 
8
+ # Middleware to handle CORS (optional, but useful if Testing4 calls this API)
9
+ app.add_middleware(
10
+ CORSMiddleware,
11
+ allow_origins=["*"], # Adjust as needed for security
12
+ allow_credentials=True,
13
+ allow_methods=["*"],
14
+ allow_headers=["*"],
15
+ )
16
+
17
+ # Load LoRA weights globally
18
  lora_weights = None
19
 
20
  @app.on_event("startup")
21
+ async def startup_event():
22
  global lora_weights
23
  lora_path = "./lora_file.pth"
24
  if os.path.exists(lora_path):
 
27
  lora_weights = base64.b64encode(f.read()).decode("utf-8")
28
  print("LoRA weights loaded and preprocessed successfully.")
29
  else:
30
+ print("LoRA file not found during startup.")
31
  raise HTTPException(status_code=500, detail="LoRA file not found.")
32
 
33
  @app.post("/modify-prompt")