Spaces:
Sleeping
Sleeping
Rajan Sharma
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
# app.py
|
| 2 |
-
# app.py
|
| 3 |
from __future__ import annotations
|
| 4 |
import os
|
| 5 |
import traceback
|
|
@@ -110,8 +109,9 @@ def handle(user_msg: str, history_messages: List[Dict[str, str]], files: list) -
|
|
| 110 |
agent = create_pandas_dataframe_agent(
|
| 111 |
llm,
|
| 112 |
df,
|
| 113 |
-
agent_type=AgentType.OPENAI_FUNCTIONS,
|
| 114 |
-
verbose=True
|
|
|
|
| 115 |
)
|
| 116 |
|
| 117 |
# Run the agent with the user's scenario text. The agent will
|
|
@@ -126,12 +126,10 @@ def handle(user_msg: str, history_messages: List[Dict[str, str]], files: list) -
|
|
| 126 |
|
| 127 |
# --- ORIGINAL LOGIC: Fallback for scenarios without files or general chat ---
|
| 128 |
elif is_healthcare_scenario(safe_in, bool(file_paths)) and USE_SCENARIO_ENGINE:
|
| 129 |
-
|
| 130 |
-
# relying on the original deterministic analysis logic.
|
| 131 |
-
registry = DataRegistry() # This part might be simplified if files always trigger the agent
|
| 132 |
rag = RAGIndex()
|
| 133 |
try:
|
| 134 |
-
ing = extract_text_from_files(file_paths)
|
| 135 |
rag.add(ing.get("chunks", []))
|
| 136 |
except Exception as e:
|
| 137 |
log_event("rag_ingest_error", None, {"err": str(e)})
|
|
@@ -204,7 +202,6 @@ with gr.Blocks(analytics_enabled=False) as demo:
|
|
| 204 |
ping_btn.click(lambda: ping_cohere(), outputs=[ping_out])
|
| 205 |
|
| 206 |
if __name__ == "__main__":
|
| 207 |
-
# Ensure you have your COHERE_API_KEY set as an environment variable
|
| 208 |
if not os.getenv("COHERE_API_KEY"):
|
| 209 |
print("🔴 COHERE_API_KEY environment variable not set. Application may not function correctly.")
|
| 210 |
|
|
|
|
| 1 |
# app.py
|
|
|
|
| 2 |
from __future__ import annotations
|
| 3 |
import os
|
| 4 |
import traceback
|
|
|
|
| 109 |
agent = create_pandas_dataframe_agent(
|
| 110 |
llm,
|
| 111 |
df,
|
| 112 |
+
agent_type=AgentType.OPENAI_FUNCTIONS,
|
| 113 |
+
verbose=True,
|
| 114 |
+
allow_dangerous_code=True # <-- THE FIX IS HERE
|
| 115 |
)
|
| 116 |
|
| 117 |
# Run the agent with the user's scenario text. The agent will
|
|
|
|
| 126 |
|
| 127 |
# --- ORIGINAL LOGIC: Fallback for scenarios without files or general chat ---
|
| 128 |
elif is_healthcare_scenario(safe_in, bool(file_paths)) and USE_SCENARIO_ENGINE:
|
| 129 |
+
registry = DataRegistry()
|
|
|
|
|
|
|
| 130 |
rag = RAGIndex()
|
| 131 |
try:
|
| 132 |
+
ing = extract_text_from_files(file_paths)
|
| 133 |
rag.add(ing.get("chunks", []))
|
| 134 |
except Exception as e:
|
| 135 |
log_event("rag_ingest_error", None, {"err": str(e)})
|
|
|
|
| 202 |
ping_btn.click(lambda: ping_cohere(), outputs=[ping_out])
|
| 203 |
|
| 204 |
if __name__ == "__main__":
|
|
|
|
| 205 |
if not os.getenv("COHERE_API_KEY"):
|
| 206 |
print("🔴 COHERE_API_KEY environment variable not set. Application may not function correctly.")
|
| 207 |
|