Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
# app.py - FastAPI application
|
2 |
import os
|
3 |
import sys
|
4 |
import json
|
@@ -11,6 +10,14 @@ import torch
|
|
11 |
from datetime import datetime
|
12 |
from pydantic import BaseModel
|
13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
# Configuration
|
15 |
persistent_dir = "/data/hf_cache"
|
16 |
model_cache_dir = os.path.join(persistent_dir, "txagent_models")
|
@@ -28,11 +35,6 @@ os.makedirs(report_dir, exist_ok=True)
|
|
28 |
os.environ["HF_HOME"] = model_cache_dir
|
29 |
os.environ["TRANSFORMERS_CACHE"] = model_cache_dir
|
30 |
|
31 |
-
# Set up Python path
|
32 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
33 |
-
src_path = os.path.abspath(os.path.join(current_dir, "src"))
|
34 |
-
sys.path.insert(0, src_path)
|
35 |
-
|
36 |
# Request models
|
37 |
class ChatRequest(BaseModel):
|
38 |
message: str
|
@@ -70,7 +72,9 @@ async def startup_event():
|
|
70 |
global agent
|
71 |
try:
|
72 |
agent = init_agent()
|
|
|
73 |
except Exception as e:
|
|
|
74 |
raise RuntimeError(f"Failed to initialize agent: {str(e)}")
|
75 |
|
76 |
def init_agent():
|
|
|
|
|
1 |
import os
|
2 |
import sys
|
3 |
import json
|
|
|
10 |
from datetime import datetime
|
11 |
from pydantic import BaseModel
|
12 |
|
13 |
+
# Add src directory to Python path
|
14 |
+
current_dir = os.path.dirname(os.path.abspath(__file__))
|
15 |
+
src_path = os.path.abspath(os.path.join(current_dir, "src"))
|
16 |
+
sys.path.insert(0, src_path)
|
17 |
+
|
18 |
+
# Now import TxAgent after adding to path
|
19 |
+
from txagent.txagent import TxAgent
|
20 |
+
|
21 |
# Configuration
|
22 |
persistent_dir = "/data/hf_cache"
|
23 |
model_cache_dir = os.path.join(persistent_dir, "txagent_models")
|
|
|
35 |
os.environ["HF_HOME"] = model_cache_dir
|
36 |
os.environ["TRANSFORMERS_CACHE"] = model_cache_dir
|
37 |
|
|
|
|
|
|
|
|
|
|
|
38 |
# Request models
|
39 |
class ChatRequest(BaseModel):
|
40 |
message: str
|
|
|
72 |
global agent
|
73 |
try:
|
74 |
agent = init_agent()
|
75 |
+
logger.info("TxAgent initialized successfully")
|
76 |
except Exception as e:
|
77 |
+
logger.error(f"Failed to initialize agent: {str(e)}")
|
78 |
raise RuntimeError(f"Failed to initialize agent: {str(e)}")
|
79 |
|
80 |
def init_agent():
|