Spaces:
Sleeping
Sleeping
Rafael Poyiadzi Claude Opus 4.6 commited on
Commit ·
d250093
1
Parent(s): fc4341a
Clean up research column, fix header link, add test CSV
Browse filesExtract text from research column dict objects and move column to
last position. Switch schema input to Textbox for Gradio 5
compatibility. Fix everyrow link to everyrow.io and add API key info.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- app.py +28 -12
- test_crm_data_5.csv +6 -0
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
import tempfile
|
|
@@ -73,16 +74,29 @@ async def run_agent_map(api_key, file, query, effort_label, schema_json):
|
|
| 73 |
|
| 74 |
output_df = result.data
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
tmp = tempfile.NamedTemporaryFile(
|
| 77 |
delete=False, suffix=".csv", prefix="everyrow_results_"
|
| 78 |
)
|
| 79 |
output_df.to_csv(tmp.name, index=False)
|
| 80 |
|
| 81 |
-
return (
|
| 82 |
-
gr.update(visible=True),
|
| 83 |
-
gr.update(value=output_df, visible=True),
|
| 84 |
-
gr.update(value=tmp.name, visible=True),
|
| 85 |
-
)
|
| 86 |
|
| 87 |
|
| 88 |
with gr.Blocks(title="everyrow research") as demo:
|
|
@@ -90,7 +104,9 @@ with gr.Blocks(title="everyrow research") as demo:
|
|
| 90 |
"""
|
| 91 |
# everyrow research
|
| 92 |
Upload a CSV, describe what you want to research for each row, and get
|
| 93 |
-
enriched results powered by [everyrow](https://everyrow.
|
|
|
|
|
|
|
| 94 |
"""
|
| 95 |
)
|
| 96 |
|
|
@@ -117,11 +133,11 @@ with gr.Blocks(title="everyrow research") as demo:
|
|
| 117 |
label="Effort level",
|
| 118 |
)
|
| 119 |
|
| 120 |
-
schema = gr.
|
| 121 |
label="Response schema (optional)",
|
| 122 |
-
|
| 123 |
value="",
|
| 124 |
-
lines=
|
| 125 |
)
|
| 126 |
gr.Markdown(
|
| 127 |
'*Define output columns as `{"field_name": "type"}`. '
|
|
@@ -131,8 +147,8 @@ with gr.Blocks(title="everyrow research") as demo:
|
|
| 131 |
|
| 132 |
submit_btn = gr.Button("Run", variant="primary")
|
| 133 |
|
| 134 |
-
|
| 135 |
-
output_table = gr.Dataframe(label="Results"
|
| 136 |
download_btn = gr.File(label="Download CSV", visible=False)
|
| 137 |
|
| 138 |
def on_upload(file):
|
|
@@ -150,7 +166,7 @@ with gr.Blocks(title="everyrow research") as demo:
|
|
| 150 |
submit_btn.click(
|
| 151 |
fn=run_agent_map,
|
| 152 |
inputs=[api_key, file, query, effort, schema],
|
| 153 |
-
outputs=[
|
| 154 |
)
|
| 155 |
|
| 156 |
if __name__ == "__main__":
|
|
|
|
| 1 |
+
import ast
|
| 2 |
import json
|
| 3 |
import os
|
| 4 |
import tempfile
|
|
|
|
| 74 |
|
| 75 |
output_df = result.data
|
| 76 |
|
| 77 |
+
if "research" in output_df.columns:
|
| 78 |
+
def _extract_research(val):
|
| 79 |
+
if isinstance(val, dict):
|
| 80 |
+
return val.get("answer", str(val))
|
| 81 |
+
if isinstance(val, str):
|
| 82 |
+
try:
|
| 83 |
+
parsed = ast.literal_eval(val)
|
| 84 |
+
if isinstance(parsed, dict) and "answer" in parsed:
|
| 85 |
+
return parsed["answer"]
|
| 86 |
+
except (ValueError, SyntaxError):
|
| 87 |
+
pass
|
| 88 |
+
return val
|
| 89 |
+
|
| 90 |
+
output_df["research"] = output_df["research"].apply(_extract_research)
|
| 91 |
+
cols = [c for c in output_df.columns if c != "research"] + ["research"]
|
| 92 |
+
output_df = output_df[cols]
|
| 93 |
+
|
| 94 |
tmp = tempfile.NamedTemporaryFile(
|
| 95 |
delete=False, suffix=".csv", prefix="everyrow_results_"
|
| 96 |
)
|
| 97 |
output_df.to_csv(tmp.name, index=False)
|
| 98 |
|
| 99 |
+
return output_df, gr.update(value=tmp.name, visible=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
|
| 101 |
|
| 102 |
with gr.Blocks(title="everyrow research") as demo:
|
|
|
|
| 104 |
"""
|
| 105 |
# everyrow research
|
| 106 |
Upload a CSV, describe what you want to research for each row, and get
|
| 107 |
+
enriched results powered by [everyrow](https://everyrow.io).
|
| 108 |
+
|
| 109 |
+
Get your API key at [everyrow.io/api-key](https://everyrow.io/api-key) ($20 free credit).
|
| 110 |
"""
|
| 111 |
)
|
| 112 |
|
|
|
|
| 133 |
label="Effort level",
|
| 134 |
)
|
| 135 |
|
| 136 |
+
schema = gr.Textbox(
|
| 137 |
label="Response schema (optional)",
|
| 138 |
+
placeholder='e.g. {"country": "str", "capital": "str"}',
|
| 139 |
value="",
|
| 140 |
+
lines=3,
|
| 141 |
)
|
| 142 |
gr.Markdown(
|
| 143 |
'*Define output columns as `{"field_name": "type"}`. '
|
|
|
|
| 147 |
|
| 148 |
submit_btn = gr.Button("Run", variant="primary")
|
| 149 |
|
| 150 |
+
gr.Markdown("### Results")
|
| 151 |
+
output_table = gr.Dataframe(label="Results")
|
| 152 |
download_btn = gr.File(label="Download CSV", visible=False)
|
| 153 |
|
| 154 |
def on_upload(file):
|
|
|
|
| 166 |
submit_btn.click(
|
| 167 |
fn=run_agent_map,
|
| 168 |
inputs=[api_key, file, query, effort, schema],
|
| 169 |
+
outputs=[output_table, download_btn],
|
| 170 |
)
|
| 171 |
|
| 172 |
if __name__ == "__main__":
|
test_crm_data_5.csv
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
company_name,contact_name,email_address
|
| 2 |
+
Master Card,Misty Carder,security@mastercard-intl.com
|
| 3 |
+
Nvidia Inc.,Jensen Miller,j.miller@nvidia-tech.com
|
| 4 |
+
Enel S.p.A.,Flavio Cattaneo,
|
| 5 |
+
Pallow Alto,Nikesh Arora,
|
| 6 |
+
Airbnb Corp,Brian Chesky-Jr,
|