Update app.py
Browse files
app.py
CHANGED
|
@@ -8,10 +8,9 @@ import hashlib
|
|
| 8 |
import shutil
|
| 9 |
import re
|
| 10 |
from datetime import datetime
|
| 11 |
-
import time
|
| 12 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 13 |
|
| 14 |
-
# Setup
|
| 15 |
persistent_dir = "/data/hf_cache"
|
| 16 |
os.makedirs(persistent_dir, exist_ok=True)
|
| 17 |
|
|
@@ -20,16 +19,13 @@ tool_cache_dir = os.path.join(persistent_dir, "tool_cache")
|
|
| 20 |
file_cache_dir = os.path.join(persistent_dir, "cache")
|
| 21 |
report_dir = os.path.join(persistent_dir, "reports")
|
| 22 |
|
| 23 |
-
for
|
| 24 |
-
os.makedirs(
|
| 25 |
|
| 26 |
os.environ["HF_HOME"] = model_cache_dir
|
| 27 |
os.environ["TRANSFORMERS_CACHE"] = model_cache_dir
|
| 28 |
|
| 29 |
-
|
| 30 |
-
src_path = os.path.abspath(os.path.join(current_dir, "src"))
|
| 31 |
-
sys.path.insert(0, src_path)
|
| 32 |
-
|
| 33 |
from txagent.txagent import TxAgent
|
| 34 |
|
| 35 |
MAX_MODEL_TOKENS = 32768
|
|
@@ -162,7 +158,7 @@ def process_final_report(agent, file, chatbot_state: List[Dict[str, str]]) -> Tu
|
|
| 162 |
return messages, report_path
|
| 163 |
|
| 164 |
def create_ui(agent):
|
| 165 |
-
with gr.Blocks(css
|
| 166 |
html, body, .gradio-container {
|
| 167 |
height: 100vh;
|
| 168 |
background-color: #111827;
|
|
@@ -190,24 +186,24 @@ def create_ui(agent):
|
|
| 190 |
border: 1px solid #374151;
|
| 191 |
border-radius: 8px;
|
| 192 |
}
|
| 193 |
-
|
| 194 |
-
gr.Markdown(
|
| 195 |
with gr.Row():
|
| 196 |
with gr.Column(scale=3):
|
| 197 |
chatbot = gr.Chatbot(
|
| 198 |
-
label
|
| 199 |
height=700,
|
| 200 |
-
type
|
| 201 |
avatar_images=[
|
| 202 |
-
|
| 203 |
-
|
| 204 |
]
|
| 205 |
)
|
| 206 |
with gr.Column(scale=1):
|
| 207 |
with gr.Row():
|
| 208 |
-
file_upload = gr.File(label
|
| 209 |
-
analyze_btn = gr.Button(
|
| 210 |
-
report_output = gr.File(label
|
| 211 |
|
| 212 |
chatbot_state = gr.State(value=[])
|
| 213 |
|
|
@@ -219,11 +215,11 @@ def create_ui(agent):
|
|
| 219 |
|
| 220 |
return demo
|
| 221 |
|
| 222 |
-
if __name__ ==
|
| 223 |
try:
|
| 224 |
agent = init_agent()
|
| 225 |
demo = create_ui(agent)
|
| 226 |
-
demo.launch(server_name
|
| 227 |
except Exception as e:
|
| 228 |
-
print(f
|
| 229 |
sys.exit(1)
|
|
|
|
| 8 |
import shutil
|
| 9 |
import re
|
| 10 |
from datetime import datetime
|
|
|
|
| 11 |
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 12 |
|
| 13 |
+
# Setup directories
|
| 14 |
persistent_dir = "/data/hf_cache"
|
| 15 |
os.makedirs(persistent_dir, exist_ok=True)
|
| 16 |
|
|
|
|
| 19 |
file_cache_dir = os.path.join(persistent_dir, "cache")
|
| 20 |
report_dir = os.path.join(persistent_dir, "reports")
|
| 21 |
|
| 22 |
+
for d in [model_cache_dir, tool_cache_dir, file_cache_dir, report_dir]:
|
| 23 |
+
os.makedirs(d, exist_ok=True)
|
| 24 |
|
| 25 |
os.environ["HF_HOME"] = model_cache_dir
|
| 26 |
os.environ["TRANSFORMERS_CACHE"] = model_cache_dir
|
| 27 |
|
| 28 |
+
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "src")))
|
|
|
|
|
|
|
|
|
|
| 29 |
from txagent.txagent import TxAgent
|
| 30 |
|
| 31 |
MAX_MODEL_TOKENS = 32768
|
|
|
|
| 158 |
return messages, report_path
|
| 159 |
|
| 160 |
def create_ui(agent):
|
| 161 |
+
with gr.Blocks(css="""
|
| 162 |
html, body, .gradio-container {
|
| 163 |
height: 100vh;
|
| 164 |
background-color: #111827;
|
|
|
|
| 186 |
border: 1px solid #374151;
|
| 187 |
border-radius: 8px;
|
| 188 |
}
|
| 189 |
+
""") as demo:
|
| 190 |
+
gr.Markdown("""<h2 style='color:#60a5fa'>🩺 Patient History AI Assistant</h2><p>Upload a clinical Excel file and receive a structured diagnostic summary.</p>""")
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column(scale=3):
|
| 193 |
chatbot = gr.Chatbot(
|
| 194 |
+
label="Clinical Assistant",
|
| 195 |
height=700,
|
| 196 |
+
type="messages",
|
| 197 |
avatar_images=[
|
| 198 |
+
"https://ui-avatars.com/api/?name=AI&background=2563eb&color=fff&size=128",
|
| 199 |
+
"https://ui-avatars.com/api/?name=You&background=374151&color=fff&size=128"
|
| 200 |
]
|
| 201 |
)
|
| 202 |
with gr.Column(scale=1):
|
| 203 |
with gr.Row():
|
| 204 |
+
file_upload = gr.File(label="", file_types=[".xlsx"], elem_id="upload-btn")
|
| 205 |
+
analyze_btn = gr.Button("🧠 Analyze", variant="primary")
|
| 206 |
+
report_output = gr.File(label="Download Report", visible=False, interactive=False)
|
| 207 |
|
| 208 |
chatbot_state = gr.State(value=[])
|
| 209 |
|
|
|
|
| 215 |
|
| 216 |
return demo
|
| 217 |
|
| 218 |
+
if __name__ == "__main__":
|
| 219 |
try:
|
| 220 |
agent = init_agent()
|
| 221 |
demo = create_ui(agent)
|
| 222 |
+
demo.launch(server_name="0.0.0.0", server_port=7860, allowed_paths=["/data/hf_cache/reports"], share=False)
|
| 223 |
except Exception as e:
|
| 224 |
+
print(f"Error: {str(e)}")
|
| 225 |
sys.exit(1)
|