Rajan Sharma commited on
Commit
cb8bf64
·
verified ·
1 Parent(s): b500d63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -7
app.py CHANGED
@@ -3,7 +3,7 @@ from __future__ import annotations
3
  import os
4
  import traceback
5
  import regex as re2
6
- from typing import List, Tuple, Dict, Any
7
 
8
  import gradio as gr
9
  import pandas as pd
@@ -16,7 +16,7 @@ from langchain_experimental.agents.agent_toolkits import create_pandas_dataframe
16
 
17
  # --- LOCAL MODULE IMPORTS ---
18
  from settings import (
19
- HEALTHCARE_SETTINGS, GENERAL_CONVERSATION_PROMPT, USE_SCENARIO_ENGINE, DEBUG_PLAN,
20
  COHERE_MODEL_PRIMARY, COHERE_TIMEOUT_S, USE_OPEN_FALLBACKS
21
  )
22
  from audit_log import log_event
@@ -31,7 +31,7 @@ def load_markdown_text(filepath: str) -> str:
31
  with open(filepath, 'r', encoding='utf-8') as f:
32
  return f.read()
33
  except FileNotFoundError:
34
- return f"**Error:** The document `{os.path.basename(filepath)}` was not found. Please ensure it is in the same directory as the application."
35
 
36
  def _sanitize_text(s: str) -> str:
37
  if not isinstance(s, str): return s
@@ -83,7 +83,21 @@ def handle(user_msg: str, files: list) -> str:
83
  llm = ChatCohere(model=COHERE_MODEL_PRIMARY, temperature=0)
84
  enhanced_prompt = _create_enhanced_prompt(safe_in)
85
 
86
- AGENT_PREFIX = """...""" # Your perfected agent prefix remains here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
 
88
  agent = create_pandas_dataframe_agent(
89
  llm, dataframes, agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
@@ -138,15 +152,18 @@ with gr.Blocks(theme="soft", css="style.css") as demo:
138
  with gr.Column(scale=2):
139
  with gr.Tabs():
140
  with gr.TabItem("Current Assessment", id=0):
141
- chat_history_output = gr.Chatbot(label="Analysis Output", bubble_full_width=True, height=600)
 
 
 
 
142
  with gr.TabItem("Assessment History", id=1):
143
  gr.Markdown("## Review Past Assessments")
144
  history_dropdown = gr.Dropdown(label="Select an assessment to review", choices=[])
145
  history_display = gr.Markdown(label="Selected Assessment Details")
146
 
147
  # --- FOOTER FOR LEGAL LINKS ---
148
- with gr.Row():
149
- gr.Markdown("---")
150
  with gr.Row():
151
  privacy_link = gr.Button("Privacy Policy", variant="link")
152
  terms_link = gr.Button("Terms of Service", variant="link")
 
3
  import os
4
  import traceback
5
  import regex as re2
6
+ from typing import List, Dict, Any
7
 
8
  import gradio as gr
9
  import pandas as pd
 
16
 
17
  # --- LOCAL MODULE IMPORTS ---
18
  from settings import (
19
+ HEALTHCARE_SETTINGS, GENERAL_CONVERSATION_PROMPT,
20
  COHERE_MODEL_PRIMARY, COHERE_TIMEOUT_S, USE_OPEN_FALLBACKS
21
  )
22
  from audit_log import log_event
 
31
  with open(filepath, 'r', encoding='utf-8') as f:
32
  return f.read()
33
  except FileNotFoundError:
34
+ return f"**Error:** The document `{os.path.basename(filepath)}` was not found."
35
 
36
  def _sanitize_text(s: str) -> str:
37
  if not isinstance(s, str): return s
 
83
  llm = ChatCohere(model=COHERE_MODEL_PRIMARY, temperature=0)
84
  enhanced_prompt = _create_enhanced_prompt(safe_in)
85
 
86
+ AGENT_PREFIX = """
87
+ You are a data analysis agent. You have access to one or more pandas dataframes.
88
+ You MUST respond in one of two formats.
89
+
90
+ FORMAT 1: To perform a task. Your response must be a single block of text with ONLY these three sections:
91
+ Thought: Your step-by-step reasoning.
92
+ Action: python_repl_ast
93
+ Action Input: The Python code to run.
94
+
95
+ FORMAT 2: To give the final answer. Your response must be a single block of text with ONLY these two sections:
96
+ Thought: I have now answered all the user's questions and can provide the final report.
97
+ Final Answer: The complete answer, structured as the user requested.
98
+
99
+ CRITICAL RULE: NEVER combine `Action` and `Final Answer` in the same response. Choose one format.
100
+ """
101
 
102
  agent = create_pandas_dataframe_agent(
103
  llm, dataframes, agent_type=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
 
152
  with gr.Column(scale=2):
153
  with gr.Tabs():
154
  with gr.TabItem("Current Assessment", id=0):
155
+ chat_history_output = gr.Chatbot(
156
+ label="Analysis Output",
157
+ type="messages", # <-- THE FINAL FIX IS HERE
158
+ height=600
159
+ )
160
  with gr.TabItem("Assessment History", id=1):
161
  gr.Markdown("## Review Past Assessments")
162
  history_dropdown = gr.Dropdown(label="Select an assessment to review", choices=[])
163
  history_display = gr.Markdown(label="Selected Assessment Details")
164
 
165
  # --- FOOTER FOR LEGAL LINKS ---
166
+ with gr.Row(): gr.Markdown("---")
 
167
  with gr.Row():
168
  privacy_link = gr.Button("Privacy Policy", variant="link")
169
  terms_link = gr.Button("Terms of Service", variant="link")