Spaces:
Build error
Build error
Fix layout
Browse files
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 + [
|
|
|
|
|
|
|
| 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 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
|
|
|
|
|
|
| 304 |
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
| 323 |
-
|
| 324 |
-
|
| 325 |
-
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
|
|
|
|
|
|
|
|
|
| 329 |
|
| 330 |
-
|
| 331 |
generate_cells,
|
| 332 |
inputs=[dataset_name],
|
| 333 |
outputs=[chatbot],
|
| 334 |
)
|
| 335 |
|
| 336 |
-
|
| 337 |
-
with gr.
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
| 364 |
-
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 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()
|