asoria HF staff commited on
Commit
9f3ff28
·
1 Parent(s): 777edd0

Fix layout

Browse files
Files changed (1) hide show
  1. app.py +79 -75
app.py CHANGED
@@ -65,8 +65,8 @@ following schema, including the leading and trailing "```json" and "```":
65
  }
66
  ]
67
  ```
68
- """
69
-
70
  return format_instructions
71
 
72
 
@@ -208,7 +208,7 @@ def generate_cells(dataset_id):
208
  prompt = generate_eda_prompt(features, df, first_code)
209
  messages = [gr.ChatMessage(role="user", content=prompt)]
210
  yield messages + [gr.ChatMessage(role="assistant", content="⏳ _Starting task..._")]
211
-
212
  prompt_messages = [{"role": "user", "content": prompt}]
213
  output = inference_client.chat_completion(
214
  messages=prompt_messages, stream=True, max_tokens=2500
@@ -230,7 +230,9 @@ def generate_cells(dataset_id):
230
  formatted_prompt = generate_mapping_prompt(GENERATED_TEXT)
231
  logging.info(formatted_prompt)
232
  prompt_messages = [{"role": "user", "content": formatted_prompt}]
233
- yield messages + [gr.ChatMessage(role="assistant", content="⏳ _Generating notebook..._")]
 
 
234
 
235
  output = inference_client.chat_completion(
236
  messages=prompt_messages, stream=False, max_tokens=2500
@@ -239,7 +241,6 @@ def generate_cells(dataset_id):
239
  logging.info("---> Model output")
240
  logging.info(cells_txt)
241
 
242
-
243
  commands = get_txt_from_output(cells_txt)
244
  html_code = f"<iframe src='https://huggingface.co/datasets/{dataset_id}/embed/viewer' width='80%' height='560px'></iframe>"
245
  # Adding dataset viewer on the first part
@@ -265,6 +266,7 @@ def generate_cells(dataset_id):
265
  )
266
  yield messages
267
 
 
268
  def write_notebook_file(dataset_id, history):
269
  if not GENERATED_TEXT:
270
  raise Exception("No generated notebook")
@@ -293,83 +295,85 @@ def write_notebook_file(dataset_id, history):
293
  return history
294
 
295
 
296
- with gr.Blocks() as demo:
297
  gr.Markdown("# 🤖 Dataset notebook creator 🕵️")
298
- dataset_name = HuggingfaceHubSearch(
299
- label="Hub Dataset ID",
300
- placeholder="Search for dataset id on Huggingface",
301
- search_type="dataset",
302
- value="",
303
- )
 
 
304
 
305
- @gr.render(inputs=dataset_name)
306
- def embed(name):
307
- if not name:
308
- return gr.Markdown("### No dataset provided")
309
- html_code = f"""
310
- <iframe
311
- src="https://huggingface.co/datasets/{name}/embed/viewer/default/train"
312
- frameborder="0"
313
- width="100%"
314
- height="350px"
315
- ></iframe>
316
- """
317
- return gr.HTML(value=html_code)
318
-
319
- generate_cells_btn = gr.Button("Generate notebook")
320
-
321
- chatbot = gr.Chatbot(
322
- label="Results",
323
- type="messages",
324
- avatar_images=(
325
- None,
326
- None,
327
- ),
328
- )
 
 
 
329
 
330
- generate_cells_btn.click(
331
  generate_cells,
332
  inputs=[dataset_name],
333
  outputs=[chatbot],
334
  )
335
 
336
-
337
- with gr.Row(visible=False) as auth_page:
338
- with gr.Column():
339
- gr.Markdown(
340
- "Want to push to hub? Enter your token ([settings](https://huggingface.co/settings/tokens)):"
341
- )
342
- token_box = gr.Textbox(
343
- "", label="token", placeholder="hf_xxx", type="password"
344
- )
345
- auth_error = gr.Markdown("", visible=False)
346
-
347
- push_btn = gr.Button("Push notebook to hub", visible=False)
348
- output_lbl = gr.HTML(value="", visible=False)
349
-
350
-
351
-
352
- def auth(token):
353
- if not token:
354
- return {
355
- auth_error: gr.Markdown(value="", visible=False),
356
- push_btn: gr.Button(visible=False),
357
- }
358
- return {
359
- auth_error: gr.Markdown(value="", visible=False),
360
- push_btn: gr.Button("Push notebook to hub", visible=True),
361
- }
362
-
363
- token_box.change(
364
- auth,
365
- inputs=token_box,
366
- outputs=[auth_error, push_btn],
367
- )
368
-
369
- push_btn.click(
370
- push_notebook,
371
- inputs=[dataset_name, token_box],
372
- outputs=output_lbl,
373
- )
374
 
375
  demo.launch()
 
65
  }
66
  ]
67
  ```
68
+ """
69
+
70
  return format_instructions
71
 
72
 
 
208
  prompt = generate_eda_prompt(features, df, first_code)
209
  messages = [gr.ChatMessage(role="user", content=prompt)]
210
  yield messages + [gr.ChatMessage(role="assistant", content="⏳ _Starting task..._")]
211
+
212
  prompt_messages = [{"role": "user", "content": prompt}]
213
  output = inference_client.chat_completion(
214
  messages=prompt_messages, stream=True, max_tokens=2500
 
230
  formatted_prompt = generate_mapping_prompt(GENERATED_TEXT)
231
  logging.info(formatted_prompt)
232
  prompt_messages = [{"role": "user", "content": formatted_prompt}]
233
+ yield messages + [
234
+ gr.ChatMessage(role="assistant", content="⏳ _Generating notebook..._")
235
+ ]
236
 
237
  output = inference_client.chat_completion(
238
  messages=prompt_messages, stream=False, max_tokens=2500
 
241
  logging.info("---> Model output")
242
  logging.info(cells_txt)
243
 
 
244
  commands = get_txt_from_output(cells_txt)
245
  html_code = f"<iframe src='https://huggingface.co/datasets/{dataset_id}/embed/viewer' width='80%' height='560px'></iframe>"
246
  # Adding dataset viewer on the first part
 
266
  )
267
  yield messages
268
 
269
+
270
  def write_notebook_file(dataset_id, history):
271
  if not GENERATED_TEXT:
272
  raise Exception("No generated notebook")
 
295
  return history
296
 
297
 
298
+ with gr.Blocks(fill_height=True) as demo:
299
  gr.Markdown("# 🤖 Dataset notebook creator 🕵️")
300
+ with gr.Row():
301
+ with gr.Column(scale=1):
302
+ dataset_name = HuggingfaceHubSearch(
303
+ label="Hub Dataset ID",
304
+ placeholder="Search for dataset id on Huggingface",
305
+ search_type="dataset",
306
+ value="",
307
+ )
308
 
309
+ @gr.render(inputs=dataset_name)
310
+ def embed(name):
311
+ if not name:
312
+ return gr.Markdown("### No dataset provided")
313
+ html_code = f"""
314
+ <iframe
315
+ src="https://huggingface.co/datasets/{name}/embed/viewer/default/train"
316
+ frameborder="0"
317
+ width="100%"
318
+ height="350px"
319
+ ></iframe>
320
+ """
321
+ return gr.HTML(value=html_code)
322
+
323
+ with gr.Row():
324
+ generate_eda_btn = gr.Button("Generate EDA notebook")
325
+ generate_training_btn = gr.Button("Generate Training notebook")
326
+ generate_rag_btn = gr.Button("Generate RAG notebook")
327
+ with gr.Column():
328
+ chatbot = gr.Chatbot(
329
+ label="Results",
330
+ type="messages",
331
+ avatar_images=(
332
+ None,
333
+ None,
334
+ ),
335
+ )
336
 
337
+ generate_eda_btn.click(
338
  generate_cells,
339
  inputs=[dataset_name],
340
  outputs=[chatbot],
341
  )
342
 
343
+ # with gr.Row(visible=False) as auth_page:
344
+ # with gr.Column():
345
+ # gr.Markdown(
346
+ # "Want to push to hub? Enter your token ([settings](https://huggingface.co/settings/tokens)):"
347
+ # )
348
+ # token_box = gr.Textbox(
349
+ # "", label="token", placeholder="hf_xxx", type="password"
350
+ # )
351
+ # auth_error = gr.Markdown("", visible=False)
352
+
353
+ # push_btn = gr.Button("Push notebook to hub", visible=False)
354
+ # output_lbl = gr.HTML(value="", visible=False)
355
+
356
+ # def auth(token):
357
+ # if not token:
358
+ # return {
359
+ # auth_error: gr.Markdown(value="", visible=False),
360
+ # push_btn: gr.Button(visible=False),
361
+ # }
362
+ # return {
363
+ # auth_error: gr.Markdown(value="", visible=False),
364
+ # push_btn: gr.Button("Push notebook to hub", visible=True),
365
+ # }
366
+
367
+ # token_box.change(
368
+ # auth,
369
+ # inputs=token_box,
370
+ # outputs=[auth_error, push_btn],
371
+ # )
372
+
373
+ # push_btn.click(
374
+ # push_notebook,
375
+ # inputs=[dataset_name, token_box],
376
+ # outputs=output_lbl,
377
+ # )
 
 
 
378
 
379
  demo.launch()