asoria HF staff commited on
Commit
421b068
1 Parent(s): 92460ff

Adding draft

Browse files
Files changed (2) hide show
  1. app.py +63 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_huggingfacehub_search import HuggingfaceHubSearch
3
+ import nbformat as nbf
4
+ from huggingface_hub import HfApi
5
+
6
+ api = HfApi()
7
+
8
+ def create_notebook_file(cell_commands, notebook_name="generated_notebook.ipynb"):
9
+ nb = nbf.v4.new_notebook()
10
+ nb['cells'] = [nbf.v4.new_code_cell(command) for command in cell_commands]
11
+
12
+ with open(notebook_name, 'w') as f:
13
+ nbf.write(nb, f)
14
+
15
+ print(f"Notebook '{notebook_name}' created successfully.")
16
+
17
+ def generate_notebook(dataset_id):
18
+ commands = [
19
+ f"from datasets import load_dataset",
20
+ f"dataset = load_dataset('{dataset_id}')",
21
+ f"dataset",
22
+ ]
23
+ notebook_name = f"{dataset_id.replace('/', '-')}.ipynb"
24
+ create_notebook_file(commands, notebook_name=notebook_name)
25
+ api.upload_file(
26
+ path_or_fileobj=notebook_name,
27
+ path_in_repo="dataset_analysis.ipynb",
28
+ repo_id="asoria/en-text",
29
+ repo_type="dataset",
30
+ )
31
+ print("Notebook uploaded to Huggingface Hub.")
32
+ link = f"https://huggingface.co/datasets/{dataset_id}/blob/main/dataset_analyst.ipynb"
33
+ return f'<a target="_blank" href="{link}" style="color: var(--link-text-color); text-decoration: underline;text-decoration-style: dotted;">See notebook</a>'
34
+
35
+
36
+
37
+ with gr.Blocks() as demo:
38
+ gr.Markdown("# 🤖 Dataset auto analyst creator 🕵️")
39
+ dataset_name = HuggingfaceHubSearch(
40
+ label="Hub Dataset ID",
41
+ placeholder="Search for dataset id on Huggingface",
42
+ search_type="dataset",
43
+ value="",
44
+ )
45
+
46
+ @gr.render(inputs=dataset_name)
47
+ def embed(name):
48
+ if not name:
49
+ return gr.Markdown("### No dataset provided")
50
+ html_code = f"""
51
+ <iframe
52
+ src="https://huggingface.co/datasets/{name}/embed/viewer/default/train"
53
+ frameborder="0"
54
+ width="100%"
55
+ height="600px"
56
+ ></iframe>
57
+ """
58
+ return gr.HTML(value=html_code)
59
+
60
+ generate_btn = gr.Button("Generate notebook")
61
+ output_lbl = gr.HTML(value="")
62
+ generate_btn.click(generate_notebook, inputs=[dataset_name], outputs=[output_lbl])
63
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio_huggingfacehub_search==0.0.7
2
+ huggingface_hub
3
+ nbformat