aliabd HF Staff commited on
Commit
ea4b928
·
verified ·
1 Parent(s): 9d141ca

Upload folder using huggingface_hub

Browse files
Files changed (4) hide show
  1. README.md +1 -1
  2. requirements.txt +2 -2
  3. run.ipynb +1 -1
  4. run.py +72 -14
README.md CHANGED
@@ -5,7 +5,7 @@ emoji: 🔥
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
- sdk_version: 4.32.1
9
  app_file: run.py
10
  pinned: false
11
  hf_oauth: true
 
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 4.36.0
9
  app_file: run.py
10
  pinned: false
11
  hf_oauth: true
requirements.txt CHANGED
@@ -1,2 +1,2 @@
1
- gradio-client @ git+https://github.com/gradio-app/gradio@bc1eff12c1e9ca93bc44348913f06466fb888f9a#subdirectory=client/python
2
- https://gradio-builds.s3.amazonaws.com/bc1eff12c1e9ca93bc44348913f06466fb888f9a/gradio-4.32.1-py3-none-any.whl
 
1
+ gradio-client @ git+https://github.com/gradio-app/gradio@a2cd8a9838864596318a686510f15e7998a27880#subdirectory=client/python
2
+ https://gradio-builds.s3.amazonaws.com/a2cd8a9838864596318a686510f15e7998a27880/gradio-4.36.0-py3-none-any.whl
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: file_component_events"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "with gr.Blocks() as demo:\n", " \n", " with gr.Row():\n", " with gr.Column():\n", " file_component = gr.File(label=\"Upload Single File\", file_count=\"single\")\n", " with gr.Column():\n", " output_file_1 = gr.File(label=\"Upload Single File Output\", file_count=\"single\")\n", " num_load_btn_1 = gr.Number(label=\"# Load Upload Single File\", value=0)\n", " file_component.upload(lambda s,n: (s, n + 1), [file_component, num_load_btn_1], [output_file_1, num_load_btn_1])\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_multiple = gr.File(label=\"Upload Multiple Files\", file_count=\"multiple\")\n", " with gr.Column():\n", " output_file_2 = gr.File(label=\"Upload Multiple Files Output\", file_count=\"multiple\")\n", " num_load_btn_2 = gr.Number(label=\"# Load Upload Multiple Files\", value=0)\n", " file_component_multiple.upload(lambda s,n: (s, n + 1), [file_component_multiple, num_load_btn_2], [output_file_2, num_load_btn_2])\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_specific = gr.File(label=\"Upload Multiple Files Image/Video\", file_count=\"multiple\", file_types=[\"image\", \"video\"])\n", " with gr.Column():\n", " output_file_3 = gr.File(label=\"Upload Multiple Files Output Image/Video\", file_count=\"multiple\")\n", " num_load_btn_3 = gr.Number(label=\"# Load Upload Multiple Files Image/Video\", value=0)\n", " file_component_specific.upload(lambda s,n: (s, n + 1), [file_component_specific, num_load_btn_3], [output_file_3, num_load_btn_3])\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_pdf = gr.File(label=\"Upload PDF File\", file_types=[\"pdf\"])\n", " with gr.Column():\n", " output_file_4 = gr.File(label=\"Upload PDF File Output\")\n", " num_load_btn_4 = gr.Number(label=\"# Load Upload PDF File\", value=0)\n", " file_component_pdf.upload(lambda s,n: (s, n + 1), [file_component_pdf, num_load_btn_4], [output_file_4, num_load_btn_4])\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_invalid = gr.File(label=\"Upload File with Invalid file_types\", file_types=[\"invalid file_type\"])\n", " with gr.Column():\n", " output_file_5 = gr.File(label=\"Upload File with Invalid file_types Output\")\n", " num_load_btn_5 = gr.Number(label=\"# Load Upload File with Invalid file_types\", value=0)\n", " file_component_invalid.upload(lambda s,n: (s, n + 1), [file_component_invalid, num_load_btn_5], [output_file_5, num_load_btn_5])\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: file_component_events"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import gradio as gr\n", "\n", "\n", "def delete_file(n: int, file: gr.DeletedFileData):\n", " return [file.file.path, n + 1]\n", "\n", "\n", "with gr.Blocks() as demo:\n", "\n", " with gr.Row():\n", " with gr.Column():\n", " file_component = gr.File(label=\"Upload Single File\", file_count=\"single\")\n", " with gr.Column():\n", " output_file_1 = gr.File(\n", " label=\"Upload Single File Output\", file_count=\"single\"\n", " )\n", " num_load_btn_1 = gr.Number(label=\"# Load Upload Single File\", value=0)\n", " file_component.upload(\n", " lambda s, n: (s, n + 1),\n", " [file_component, num_load_btn_1],\n", " [output_file_1, num_load_btn_1],\n", " )\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_multiple = gr.File(\n", " label=\"Upload Multiple Files\", file_count=\"multiple\"\n", " )\n", " with gr.Column():\n", " output_file_2 = gr.File(\n", " label=\"Upload Multiple Files Output\", file_count=\"multiple\"\n", " )\n", " num_load_btn_2 = gr.Number(label=\"# Load Upload Multiple Files\", value=0)\n", " file_component_multiple.upload(\n", " lambda s, n: (s, n + 1),\n", " [file_component_multiple, num_load_btn_2],\n", " [output_file_2, num_load_btn_2],\n", " )\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_specific = gr.File(\n", " label=\"Upload Multiple Files Image/Video\",\n", " file_count=\"multiple\",\n", " file_types=[\"image\", \"video\"],\n", " )\n", " with gr.Column():\n", " output_file_3 = gr.File(\n", " label=\"Upload Multiple Files Output Image/Video\", file_count=\"multiple\"\n", " )\n", " num_load_btn_3 = gr.Number(\n", " label=\"# Load Upload Multiple Files Image/Video\", value=0\n", " )\n", " file_component_specific.upload(\n", " lambda s, n: (s, n + 1),\n", " [file_component_specific, num_load_btn_3],\n", " [output_file_3, num_load_btn_3],\n", " )\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_pdf = gr.File(label=\"Upload PDF File\", file_types=[\"pdf\"])\n", " with gr.Column():\n", " output_file_4 = gr.File(label=\"Upload PDF File Output\")\n", " num_load_btn_4 = gr.Number(label=\"# Load Upload PDF File\", value=0)\n", " file_component_pdf.upload(\n", " lambda s, n: (s, n + 1),\n", " [file_component_pdf, num_load_btn_4],\n", " [output_file_4, num_load_btn_4],\n", " )\n", " with gr.Row():\n", " with gr.Column():\n", " file_component_invalid = gr.File(\n", " label=\"Upload File with Invalid file_types\",\n", " file_types=[\"invalid file_type\"],\n", " )\n", " with gr.Column():\n", " output_file_5 = gr.File(label=\"Upload File with Invalid file_types Output\")\n", " num_load_btn_5 = gr.Number(\n", " label=\"# Load Upload File with Invalid file_types\", value=0\n", " )\n", " file_component_invalid.upload(\n", " lambda s, n: (s, n + 1),\n", " [file_component_invalid, num_load_btn_5],\n", " [output_file_5, num_load_btn_5],\n", " )\n", " with gr.Row():\n", " with gr.Column():\n", " del_file_input = gr.File(label=\"Delete File\", file_count=\"multiple\")\n", " with gr.Column():\n", " del_file_data = gr.Textbox(label=\"Delete file data\")\n", " num_load_btn_6 = gr.Number(label=\"# Deleted File\", value=0)\n", " del_file_input.delete(\n", " delete_file,\n", " [num_load_btn_6],\n", " [del_file_data, num_load_btn_6],\n", " )\n", " # f = gr.File(label=\"Upload many File\", file_count=\"multiple\")\n", " # # f.delete(delete_file)\n", " # f.delete(delete_file, inputs=None, outputs=None)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -1,42 +1,100 @@
1
  import gradio as gr
2
 
 
 
 
 
 
3
  with gr.Blocks() as demo:
4
-
5
  with gr.Row():
6
  with gr.Column():
7
  file_component = gr.File(label="Upload Single File", file_count="single")
8
  with gr.Column():
9
- output_file_1 = gr.File(label="Upload Single File Output", file_count="single")
 
 
10
  num_load_btn_1 = gr.Number(label="# Load Upload Single File", value=0)
11
- file_component.upload(lambda s,n: (s, n + 1), [file_component, num_load_btn_1], [output_file_1, num_load_btn_1])
 
 
 
 
12
  with gr.Row():
13
  with gr.Column():
14
- file_component_multiple = gr.File(label="Upload Multiple Files", file_count="multiple")
 
 
15
  with gr.Column():
16
- output_file_2 = gr.File(label="Upload Multiple Files Output", file_count="multiple")
 
 
17
  num_load_btn_2 = gr.Number(label="# Load Upload Multiple Files", value=0)
18
- file_component_multiple.upload(lambda s,n: (s, n + 1), [file_component_multiple, num_load_btn_2], [output_file_2, num_load_btn_2])
 
 
 
 
19
  with gr.Row():
20
  with gr.Column():
21
- file_component_specific = gr.File(label="Upload Multiple Files Image/Video", file_count="multiple", file_types=["image", "video"])
 
 
 
 
22
  with gr.Column():
23
- output_file_3 = gr.File(label="Upload Multiple Files Output Image/Video", file_count="multiple")
24
- num_load_btn_3 = gr.Number(label="# Load Upload Multiple Files Image/Video", value=0)
25
- file_component_specific.upload(lambda s,n: (s, n + 1), [file_component_specific, num_load_btn_3], [output_file_3, num_load_btn_3])
 
 
 
 
 
 
 
 
26
  with gr.Row():
27
  with gr.Column():
28
  file_component_pdf = gr.File(label="Upload PDF File", file_types=["pdf"])
29
  with gr.Column():
30
  output_file_4 = gr.File(label="Upload PDF File Output")
31
  num_load_btn_4 = gr.Number(label="# Load Upload PDF File", value=0)
32
- file_component_pdf.upload(lambda s,n: (s, n + 1), [file_component_pdf, num_load_btn_4], [output_file_4, num_load_btn_4])
 
 
 
 
33
  with gr.Row():
34
  with gr.Column():
35
- file_component_invalid = gr.File(label="Upload File with Invalid file_types", file_types=["invalid file_type"])
 
 
 
36
  with gr.Column():
37
  output_file_5 = gr.File(label="Upload File with Invalid file_types Output")
38
- num_load_btn_5 = gr.Number(label="# Load Upload File with Invalid file_types", value=0)
39
- file_component_invalid.upload(lambda s,n: (s, n + 1), [file_component_invalid, num_load_btn_5], [output_file_5, num_load_btn_5])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  if __name__ == "__main__":
42
  demo.launch()
 
1
  import gradio as gr
2
 
3
+
4
+ def delete_file(n: int, file: gr.DeletedFileData):
5
+ return [file.file.path, n + 1]
6
+
7
+
8
  with gr.Blocks() as demo:
9
+
10
  with gr.Row():
11
  with gr.Column():
12
  file_component = gr.File(label="Upload Single File", file_count="single")
13
  with gr.Column():
14
+ output_file_1 = gr.File(
15
+ label="Upload Single File Output", file_count="single"
16
+ )
17
  num_load_btn_1 = gr.Number(label="# Load Upload Single File", value=0)
18
+ file_component.upload(
19
+ lambda s, n: (s, n + 1),
20
+ [file_component, num_load_btn_1],
21
+ [output_file_1, num_load_btn_1],
22
+ )
23
  with gr.Row():
24
  with gr.Column():
25
+ file_component_multiple = gr.File(
26
+ label="Upload Multiple Files", file_count="multiple"
27
+ )
28
  with gr.Column():
29
+ output_file_2 = gr.File(
30
+ label="Upload Multiple Files Output", file_count="multiple"
31
+ )
32
  num_load_btn_2 = gr.Number(label="# Load Upload Multiple Files", value=0)
33
+ file_component_multiple.upload(
34
+ lambda s, n: (s, n + 1),
35
+ [file_component_multiple, num_load_btn_2],
36
+ [output_file_2, num_load_btn_2],
37
+ )
38
  with gr.Row():
39
  with gr.Column():
40
+ file_component_specific = gr.File(
41
+ label="Upload Multiple Files Image/Video",
42
+ file_count="multiple",
43
+ file_types=["image", "video"],
44
+ )
45
  with gr.Column():
46
+ output_file_3 = gr.File(
47
+ label="Upload Multiple Files Output Image/Video", file_count="multiple"
48
+ )
49
+ num_load_btn_3 = gr.Number(
50
+ label="# Load Upload Multiple Files Image/Video", value=0
51
+ )
52
+ file_component_specific.upload(
53
+ lambda s, n: (s, n + 1),
54
+ [file_component_specific, num_load_btn_3],
55
+ [output_file_3, num_load_btn_3],
56
+ )
57
  with gr.Row():
58
  with gr.Column():
59
  file_component_pdf = gr.File(label="Upload PDF File", file_types=["pdf"])
60
  with gr.Column():
61
  output_file_4 = gr.File(label="Upload PDF File Output")
62
  num_load_btn_4 = gr.Number(label="# Load Upload PDF File", value=0)
63
+ file_component_pdf.upload(
64
+ lambda s, n: (s, n + 1),
65
+ [file_component_pdf, num_load_btn_4],
66
+ [output_file_4, num_load_btn_4],
67
+ )
68
  with gr.Row():
69
  with gr.Column():
70
+ file_component_invalid = gr.File(
71
+ label="Upload File with Invalid file_types",
72
+ file_types=["invalid file_type"],
73
+ )
74
  with gr.Column():
75
  output_file_5 = gr.File(label="Upload File with Invalid file_types Output")
76
+ num_load_btn_5 = gr.Number(
77
+ label="# Load Upload File with Invalid file_types", value=0
78
+ )
79
+ file_component_invalid.upload(
80
+ lambda s, n: (s, n + 1),
81
+ [file_component_invalid, num_load_btn_5],
82
+ [output_file_5, num_load_btn_5],
83
+ )
84
+ with gr.Row():
85
+ with gr.Column():
86
+ del_file_input = gr.File(label="Delete File", file_count="multiple")
87
+ with gr.Column():
88
+ del_file_data = gr.Textbox(label="Delete file data")
89
+ num_load_btn_6 = gr.Number(label="# Deleted File", value=0)
90
+ del_file_input.delete(
91
+ delete_file,
92
+ [num_load_btn_6],
93
+ [del_file_data, num_load_btn_6],
94
+ )
95
+ # f = gr.File(label="Upload many File", file_count="multiple")
96
+ # # f.delete(delete_file)
97
+ # f.delete(delete_file, inputs=None, outputs=None)
98
 
99
  if __name__ == "__main__":
100
  demo.launch()