chabane commited on
Commit
4d312cc
·
1 Parent(s): 571f848

modify the prompt for the user in plot

Browse files
Files changed (1) hide show
  1. main.py +40 -16
main.py CHANGED
@@ -56,7 +56,7 @@ try:
56
  deepseek_model = AutoModelForCausalLM.from_pretrained(deepseek_dir, trust_remote_code=True)
57
  generator = pipeline("text-generation", model=deepseek_model, tokenizer=deepseek_tokenizer)
58
 
59
- print("[Info] facebook/bart-large-cnn is installed")
60
  except Exception as exp:
61
  print("Can't load the model deepseek-ai/deepseek-coder-1.3b-instruct")
62
  print(f"[Error] {str(exp)}")
@@ -165,14 +165,34 @@ async def plot(user_need:str=Form(...),file:UploadFile=File(...)):
165
 
166
  df = pd.read_excel(io=io.BytesIO(file_bytes))
167
 
168
- message = f"""
169
- You are a helpful assistant that helps users write Python code.
170
- ## Requirements:
171
- -you will be given a task and you will write the code to solve the task.
172
- -you have a dataset called **df** contains the following information:
173
- df.columns:{df.columns.to_list()}
174
- df.dtypes:{df.dtypes.to_dict()}
175
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  -you have to write the code to solve the task using the dataset df.
177
  -you can use pandas to manipulate the dataframe.
178
  -you can use matplotlib to plot the data.
@@ -186,23 +206,27 @@ df.dtypes:{df.dtypes.to_dict()}
186
  -you have to write the code in a markdown code block.
187
  -make sure that the type of the chart is compatible with the dtypes of the columns
188
  -use only the column specified in the task.
 
 
 
189
  -you have to extract the column names and the plot type from the prompt bellow and use them in the code.
190
  -if the user task is not clear or there is an error like the column names are not in the dataframe, raise an
191
  error.
192
- ##Prompt: {user_need}.
193
- """
194
- print(" MESSAGE \n"+message)
 
195
  global generator
196
- output = generator(message, max_length=1000)
197
- print(f'OUTPUT {output[0]["generated_text"]}')
198
- match = re.search(r'```python(.*?)```', output[0]["generated_text"], re.DOTALL)
199
 
200
  code =''
201
  if not match:
202
  return JSONResponse(content={"error": "No Code was Generated"},status_code=403)
203
 
204
  code = match.group(1).replace("plt.show()\n","")
205
- print(code)
206
 
207
  safe_globals={
208
  "plt": plt,
 
56
  deepseek_model = AutoModelForCausalLM.from_pretrained(deepseek_dir, trust_remote_code=True)
57
  generator = pipeline("text-generation", model=deepseek_model, tokenizer=deepseek_tokenizer)
58
 
59
+ print("[Info] deepseek-ai/deepseek-coder-1.3b-instruct is installed")
60
  except Exception as exp:
61
  print("Can't load the model deepseek-ai/deepseek-coder-1.3b-instruct")
62
  print(f"[Error] {str(exp)}")
 
165
 
166
  df = pd.read_excel(io=io.BytesIO(file_bytes))
167
 
168
+ # message = f"""
169
+ #You are a helpful assistant that helps users write Python code.
170
+ ### Requirements:
171
+ #-you will be given a task and you will write the code to solve the task.
172
+ #-you have a dataset called **df** contains the following information:
173
+ #df.columns:{df.columns.to_list()}
174
+ #df.dtypes:{df.dtypes.to_dict()}
175
+ #
176
+ #-you have to write the code to solve the task using the dataset df.
177
+ #-you can use pandas to manipulate the dataframe.
178
+ #-you can use matplotlib to plot the data.
179
+ #-you can use seaborn to plot the data.
180
+ #-don't use print or input statements in the code.
181
+ #-don't use any other libraries except pandas, matplotlib, seaborn.
182
+ #-don't use any other functions except the ones provided in the libraries.
183
+ #-don't write the code for the dataframe creation.
184
+ #-check if the columns has a nan values and raise exception if yes .
185
+ #-exclude plt.show() from the code.
186
+ #-you have to write the code in a markdown code block.
187
+ #-make sure that the type of the chart is compatible with the dtypes of the columns
188
+ #-use only the column specified in the task.
189
+ #-you have to extract the column names and the plot type from the prompt bellow and use them in the code.
190
+ #-if the user task is not clear or there is an error like the column names are not in the dataframe, raise an
191
+ #error.
192
+ ###Prompt: {user_need}.
193
+ # """
194
+ prompt = [
195
+ {"role": "system", "content": f'''You are a helpful assistant that helps users write Python code.
196
  -you have to write the code to solve the task using the dataset df.
197
  -you can use pandas to manipulate the dataframe.
198
  -you can use matplotlib to plot the data.
 
206
  -you have to write the code in a markdown code block.
207
  -make sure that the type of the chart is compatible with the dtypes of the columns
208
  -use only the column specified in the task.
209
+ -you have an information about the dataframe called df contains the following information:
210
+ df.columns:{df.columns.to_list()}
211
+ df.dtypes:{df.dtypes.to_dict()}
212
  -you have to extract the column names and the plot type from the prompt bellow and use them in the code.
213
  -if the user task is not clear or there is an error like the column names are not in the dataframe, raise an
214
  error.
215
+ '''},
216
+ {"role": "user", "content": user_need},
217
+ ]
218
+
219
  global generator
220
+ output = generator(prompt, max_length=1000)
221
+
222
+ match = re.search(r'```python(.*?)```', output[0]['generated_text'][2]['content'], re.DOTALL)
223
 
224
  code =''
225
  if not match:
226
  return JSONResponse(content={"error": "No Code was Generated"},status_code=403)
227
 
228
  code = match.group(1).replace("plt.show()\n","")
229
+
230
 
231
  safe_globals={
232
  "plt": plt,