Spaces:
Running
Running
Improve prompt
Browse files- app.py +12 -11
- figures/blank.txt +0 -0
app.py
CHANGED
@@ -25,8 +25,8 @@ agent = ReactCodeAgent(
|
|
25 |
)
|
26 |
|
27 |
base_prompt = """You are an expert data analyst.
|
28 |
-
Please load the source file with pandas
|
29 |
-
According to the features you have
|
30 |
Then list 3 interesting questions that could be asked on this data, for instance about specific correlations with target variable.
|
31 |
Then answer these questions one by one, by finding the relevant numbers.
|
32 |
Meanwhile, plot some figures using matplotlib/seaborn and save them to the (already existing) folder './figures/': take care to clear each figure with plt.clf() before doing another plot.
|
@@ -35,7 +35,9 @@ In your final answer: summarize these correlations and trends
|
|
35 |
After each number derive real worlds insights, for instance: "Correlation between is_december and boredness is 1.3453, which suggest people are more bored in winter".
|
36 |
Your final answer should be a long string with at least 3 numbered and detailed parts.
|
37 |
|
38 |
-
|
|
|
|
|
39 |
"""
|
40 |
|
41 |
example_notes="""This data is about the Titanic wreck in 1912.
|
@@ -68,13 +70,12 @@ def interact_with_agent(file_input, additional_notes):
|
|
68 |
os.makedirs("./figures")
|
69 |
|
70 |
read_file = pd.read_csv(file_input)
|
71 |
-
data_structure_notes = f"""
|
72 |
-
- Description (output of .describe()):
|
73 |
{read_file.describe()}
|
74 |
- Columns with dtypes:
|
75 |
-
{read_file.dtypes}
|
76 |
-
|
77 |
-
prompt = base_prompt
|
78 |
|
79 |
if additional_notes and len(additional_notes) > 0:
|
80 |
prompt += "\nAdditional notes on the data:\n" + additional_notes
|
@@ -83,7 +84,7 @@ def interact_with_agent(file_input, additional_notes):
|
|
83 |
yield messages
|
84 |
|
85 |
plot_image_paths = {}
|
86 |
-
for msg in stream_from_transformers_agent(agent, prompt
|
87 |
messages.append(msg)
|
88 |
for image_path in get_images_in_directory("./figures"):
|
89 |
if image_path not in plot_image_paths:
|
@@ -99,10 +100,10 @@ def interact_with_agent(file_input, additional_notes):
|
|
99 |
yield messages
|
100 |
|
101 |
|
102 |
-
with gr.Blocks(
|
103 |
gr.Markdown("""# Llama-3.1 Data analyst
|
104 |
|
105 |
-
Drop a `.csv` file
|
106 |
file_input = gr.File(label="Your file to analyze")
|
107 |
text_input = gr.Textbox(
|
108 |
label="Additional notes to support the analysis"
|
|
|
25 |
)
|
26 |
|
27 |
base_prompt = """You are an expert data analyst.
|
28 |
+
Please load the source file with pandas (you cannot use 'os' module).
|
29 |
+
According to the features you have and the dta structure given below, determine which feature should be the target.
|
30 |
Then list 3 interesting questions that could be asked on this data, for instance about specific correlations with target variable.
|
31 |
Then answer these questions one by one, by finding the relevant numbers.
|
32 |
Meanwhile, plot some figures using matplotlib/seaborn and save them to the (already existing) folder './figures/': take care to clear each figure with plt.clf() before doing another plot.
|
|
|
35 |
After each number derive real worlds insights, for instance: "Correlation between is_december and boredness is 1.3453, which suggest people are more bored in winter".
|
36 |
Your final answer should be a long string with at least 3 numbered and detailed parts.
|
37 |
|
38 |
+
Source file for the data = {source_file}
|
39 |
+
Structure of the data:
|
40 |
+
{structure_notes}
|
41 |
"""
|
42 |
|
43 |
example_notes="""This data is about the Titanic wreck in 1912.
|
|
|
70 |
os.makedirs("./figures")
|
71 |
|
72 |
read_file = pd.read_csv(file_input)
|
73 |
+
data_structure_notes = f"""- Description (output of .describe()):
|
|
|
74 |
{read_file.describe()}
|
75 |
- Columns with dtypes:
|
76 |
+
{read_file.dtypes}"""
|
77 |
+
|
78 |
+
prompt = base_prompt.format(source_file=file_input, structure_notes=data_structure_notes)
|
79 |
|
80 |
if additional_notes and len(additional_notes) > 0:
|
81 |
prompt += "\nAdditional notes on the data:\n" + additional_notes
|
|
|
84 |
yield messages
|
85 |
|
86 |
plot_image_paths = {}
|
87 |
+
for msg in stream_from_transformers_agent(agent, prompt):
|
88 |
messages.append(msg)
|
89 |
for image_path in get_images_in_directory("./figures"):
|
90 |
if image_path not in plot_image_paths:
|
|
|
100 |
yield messages
|
101 |
|
102 |
|
103 |
+
with gr.Blocks() as demo:
|
104 |
gr.Markdown("""# Llama-3.1 Data analyst
|
105 |
|
106 |
+
Drop a `.csv` file below, add notes to describe this data if needed, and **Llama-3.1-70B will analyze the file content and draw figures for you!**""")
|
107 |
file_input = gr.File(label="Your file to analyze")
|
108 |
text_input = gr.Textbox(
|
109 |
label="Additional notes to support the analysis"
|
figures/blank.txt
DELETED
File without changes
|