Spaces:
Sleeping
Sleeping
Rafael Poyiadzi Claude Opus 4.6 commited on
Commit ·
bd620e6
1
Parent(s): 59ff43a
Fix PostHog api_key attribute and remove debug logging
Browse filesPostHog SDK requires `api_key` (not just `project_api_key`) for
server-side capture calls. Sets both attributes. Removes debug
prints and posthog.debug flag.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
app.py
CHANGED
|
@@ -3,6 +3,7 @@ import hashlib
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import tempfile
|
|
|
|
| 6 |
from typing import Literal
|
| 7 |
|
| 8 |
import gradio as gr
|
|
@@ -14,6 +15,7 @@ _POSTHOG_KEY = os.environ.get("POSTHOG_KEY", "")
|
|
| 14 |
_POSTHOG_HOST = os.environ.get("POSTHOG_HOST", "")
|
| 15 |
_POSTHOG_ENABLED = bool(_POSTHOG_KEY and _POSTHOG_HOST)
|
| 16 |
|
|
|
|
| 17 |
posthog.project_api_key = _POSTHOG_KEY
|
| 18 |
posthog.host = _POSTHOG_HOST
|
| 19 |
|
|
@@ -128,7 +130,7 @@ def _posthog_distinct_id(api_key: str) -> str:
|
|
| 128 |
return hashlib.sha256(api_key.encode()).hexdigest()[:16]
|
| 129 |
|
| 130 |
|
| 131 |
-
async def run_agent_map(api_key, file, query, effort_label, fields_list):
|
| 132 |
if not api_key:
|
| 133 |
raise gr.Error("Please enter your everyrow API key.")
|
| 134 |
if file is None:
|
|
@@ -159,6 +161,7 @@ async def run_agent_map(api_key, file, query, effort_label, fields_list):
|
|
| 159 |
distinct_id=distinct_id,
|
| 160 |
event="agent_map_started",
|
| 161 |
properties={
|
|
|
|
| 162 |
"effort_level": effort_label,
|
| 163 |
"row_count": len(df),
|
| 164 |
"column_count": len(df.columns),
|
|
@@ -174,7 +177,7 @@ async def run_agent_map(api_key, file, query, effort_label, fields_list):
|
|
| 174 |
posthog.capture(
|
| 175 |
distinct_id=distinct_id,
|
| 176 |
event="agent_map_failed",
|
| 177 |
-
properties={"error": str(result.error), "app": "everyrow-research-space"},
|
| 178 |
)
|
| 179 |
raise gr.Error(f"agent_map failed: {result.error}")
|
| 180 |
|
|
@@ -183,6 +186,7 @@ async def run_agent_map(api_key, file, query, effort_label, fields_list):
|
|
| 183 |
distinct_id=distinct_id,
|
| 184 |
event="agent_map_completed",
|
| 185 |
properties={
|
|
|
|
| 186 |
"output_rows": len(result.data),
|
| 187 |
"output_columns": len(result.data.columns),
|
| 188 |
"app": "everyrow-research-space",
|
|
@@ -290,6 +294,7 @@ with gr.Blocks(
|
|
| 290 |
"*Define the structured fields you want the AI to annotate for each row. Leave empty to return a single answer column.*"
|
| 291 |
)
|
| 292 |
|
|
|
|
| 293 |
fields_state = gr.State([])
|
| 294 |
|
| 295 |
@gr.render(inputs=fields_state)
|
|
@@ -440,7 +445,7 @@ with gr.Blocks(
|
|
| 440 |
submit_btn = gr.Button("Run", variant="primary")
|
| 441 |
|
| 442 |
# Submit: read name/desc/opts from components for freshest values
|
| 443 |
-
async def on_submit(api_key_val, file_val, query_val, effort_val, *dynamic_vals):
|
| 444 |
names = dynamic_vals[:n]
|
| 445 |
descs = dynamic_vals[n:2 * n]
|
| 446 |
opts_vals = list(dynamic_vals[2 * n:])
|
|
@@ -458,7 +463,7 @@ with gr.Blocks(
|
|
| 458 |
fields_list.append(entry)
|
| 459 |
try:
|
| 460 |
result_df, download_update = await run_agent_map(
|
| 461 |
-
api_key_val, file_val, query_val, effort_val, fields_list
|
| 462 |
)
|
| 463 |
has_research = "research" in result_df.columns
|
| 464 |
return (
|
|
@@ -484,7 +489,7 @@ with gr.Blocks(
|
|
| 484 |
|
| 485 |
submit_btn.click(
|
| 486 |
fn=on_submit,
|
| 487 |
-
inputs=[api_key, file, query, effort] + all_text_inputs,
|
| 488 |
outputs=[error_box, full_results_state, output_table, download_btn, research_toggle],
|
| 489 |
)
|
| 490 |
|
|
|
|
| 3 |
import json
|
| 4 |
import os
|
| 5 |
import tempfile
|
| 6 |
+
import uuid
|
| 7 |
from typing import Literal
|
| 8 |
|
| 9 |
import gradio as gr
|
|
|
|
| 15 |
_POSTHOG_HOST = os.environ.get("POSTHOG_HOST", "")
|
| 16 |
_POSTHOG_ENABLED = bool(_POSTHOG_KEY and _POSTHOG_HOST)
|
| 17 |
|
| 18 |
+
posthog.api_key = _POSTHOG_KEY
|
| 19 |
posthog.project_api_key = _POSTHOG_KEY
|
| 20 |
posthog.host = _POSTHOG_HOST
|
| 21 |
|
|
|
|
| 130 |
return hashlib.sha256(api_key.encode()).hexdigest()[:16]
|
| 131 |
|
| 132 |
|
| 133 |
+
async def run_agent_map(api_key, file, query, effort_label, fields_list, session_id):
|
| 134 |
if not api_key:
|
| 135 |
raise gr.Error("Please enter your everyrow API key.")
|
| 136 |
if file is None:
|
|
|
|
| 161 |
distinct_id=distinct_id,
|
| 162 |
event="agent_map_started",
|
| 163 |
properties={
|
| 164 |
+
"$session_id": session_id,
|
| 165 |
"effort_level": effort_label,
|
| 166 |
"row_count": len(df),
|
| 167 |
"column_count": len(df.columns),
|
|
|
|
| 177 |
posthog.capture(
|
| 178 |
distinct_id=distinct_id,
|
| 179 |
event="agent_map_failed",
|
| 180 |
+
properties={"$session_id": session_id, "error": str(result.error), "app": "everyrow-research-space"},
|
| 181 |
)
|
| 182 |
raise gr.Error(f"agent_map failed: {result.error}")
|
| 183 |
|
|
|
|
| 186 |
distinct_id=distinct_id,
|
| 187 |
event="agent_map_completed",
|
| 188 |
properties={
|
| 189 |
+
"$session_id": session_id,
|
| 190 |
"output_rows": len(result.data),
|
| 191 |
"output_columns": len(result.data.columns),
|
| 192 |
"app": "everyrow-research-space",
|
|
|
|
| 294 |
"*Define the structured fields you want the AI to annotate for each row. Leave empty to return a single answer column.*"
|
| 295 |
)
|
| 296 |
|
| 297 |
+
session_id = gr.State(lambda: str(uuid.uuid4()))
|
| 298 |
fields_state = gr.State([])
|
| 299 |
|
| 300 |
@gr.render(inputs=fields_state)
|
|
|
|
| 445 |
submit_btn = gr.Button("Run", variant="primary")
|
| 446 |
|
| 447 |
# Submit: read name/desc/opts from components for freshest values
|
| 448 |
+
async def on_submit(api_key_val, file_val, query_val, effort_val, session_id_val, *dynamic_vals):
|
| 449 |
names = dynamic_vals[:n]
|
| 450 |
descs = dynamic_vals[n:2 * n]
|
| 451 |
opts_vals = list(dynamic_vals[2 * n:])
|
|
|
|
| 463 |
fields_list.append(entry)
|
| 464 |
try:
|
| 465 |
result_df, download_update = await run_agent_map(
|
| 466 |
+
api_key_val, file_val, query_val, effort_val, fields_list, session_id_val
|
| 467 |
)
|
| 468 |
has_research = "research" in result_df.columns
|
| 469 |
return (
|
|
|
|
| 489 |
|
| 490 |
submit_btn.click(
|
| 491 |
fn=on_submit,
|
| 492 |
+
inputs=[api_key, file, query, effort, session_id] + all_text_inputs,
|
| 493 |
outputs=[error_box, full_results_state, output_table, download_btn, research_toggle],
|
| 494 |
)
|
| 495 |
|