Ali2206 commited on
Commit
61f2003
·
verified ·
1 Parent(s): 3b1cd22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -21
app.py CHANGED
@@ -3,10 +3,10 @@ import sys
3
  import random
4
  import gradio as gr
5
 
6
- # Add `src` to import path
7
  sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
8
 
9
- from txagent.txagent import TxAgent
10
 
11
  # === Environment setup ===
12
  current_dir = os.path.dirname(os.path.abspath(__file__))
@@ -62,8 +62,18 @@ question_examples = [
62
  ["A 30-year-old patient is on Prozac for depression and now diagnosed with WHIM syndrome. Is Xolremdi suitable?"]
63
  ]
64
 
65
- agent = None # will be initialized in main
66
-
 
 
 
 
 
 
 
 
 
 
67
 
68
  # === Create Gradio UI ===
69
  def create_ui():
@@ -88,7 +98,7 @@ def create_ui():
88
 
89
  # === Chat handler (streaming)
90
  async def handle_chat(message, history, temperature, max_new_tokens, max_tokens, multi_agent, conversation, max_round):
91
- return agent.run_gradio_chat(
92
  message=message,
93
  history=history,
94
  temperature=temperature,
@@ -104,7 +114,7 @@ def create_ui():
104
  agent.update_parameters(seed=random.randint(0, 10000))
105
  new_history = history[:retry_data.index]
106
  prompt = history[retry_data.index]["content"]
107
- return agent.run_gradio_chat(
108
  message=prompt,
109
  history=new_history,
110
  temperature=temperature,
@@ -141,20 +151,6 @@ def create_ui():
141
  gr.Markdown(LICENSE)
142
  return demo
143
 
144
-
145
- # === HF Spaces + local launch entrypoint ===
146
  if __name__ == "__main__":
147
- agent = TxAgent(
148
- model_name,
149
- rag_model_name,
150
- tool_files_dict=new_tool_files,
151
- force_finish=True,
152
- enable_checker=True,
153
- step_rag_num=10,
154
- seed=100,
155
- additional_default_tools=["DirectResponse", "RequireClarification"]
156
- )
157
- agent.init_model()
158
-
159
  demo = create_ui()
160
- demo.launch(show_error=True)
 
3
  import random
4
  import gradio as gr
5
 
6
+ # Add src to path
7
  sys.path.append(os.path.join(os.path.dirname(__file__), "src"))
8
 
9
+ from txagent import TxAgent
10
 
11
  # === Environment setup ===
12
  current_dir = os.path.dirname(os.path.abspath(__file__))
 
62
  ["A 30-year-old patient is on Prozac for depression and now diagnosed with WHIM syndrome. Is Xolremdi suitable?"]
63
  ]
64
 
65
+ # Initialize agent
66
+ agent = TxAgent(
67
+ model_name,
68
+ rag_model_name,
69
+ tool_files_dict=new_tool_files,
70
+ force_finish=True,
71
+ enable_checker=True,
72
+ step_rag_num=10,
73
+ seed=100,
74
+ additional_default_tools=["DirectResponse", "RequireClarification"]
75
+ )
76
+ agent.init_model()
77
 
78
  # === Create Gradio UI ===
79
  def create_ui():
 
98
 
99
  # === Chat handler (streaming)
100
  async def handle_chat(message, history, temperature, max_new_tokens, max_tokens, multi_agent, conversation, max_round):
101
+ return await agent.run_gradio_chat(
102
  message=message,
103
  history=history,
104
  temperature=temperature,
 
114
  agent.update_parameters(seed=random.randint(0, 10000))
115
  new_history = history[:retry_data.index]
116
  prompt = history[retry_data.index]["content"]
117
+ return await agent.run_gradio_chat(
118
  message=prompt,
119
  history=new_history,
120
  temperature=temperature,
 
151
  gr.Markdown(LICENSE)
152
  return demo
153
 
 
 
154
  if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
155
  demo = create_ui()
156
+ demo.launch(show_error=True)