radames commited on
Commit
b26a569
1 Parent(s): 6881f56

Upload folder using huggingface_hub

Browse files
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ FROM python:3.9
3
+
4
+ WORKDIR /code
5
+
6
+ COPY --link --chown=1000 . .
7
+
8
+ RUN mkdir -p /tmp/cache/
9
+ RUN chmod a+rwx -R /tmp/cache/
10
+ ENV TRANSFORMERS_CACHE=/tmp/cache/
11
+
12
+ RUN pip install --no-cache-dir -r requirements.txt
13
+
14
+ ENV PYTHONUNBUFFERED=1 GRADIO_ALLOW_FLAGGING=never GRADIO_NUM_PORTS=1 GRADIO_SERVER_NAME=0.0.0.0 GRADIO_SERVER_PORT=7860 SYSTEM=spaces
15
+
16
+ CMD ["python", "space.py"]
README.md CHANGED
@@ -1,10 +1,10 @@
 
1
  ---
2
- title: Gradio Huggingfacehub Search
3
- emoji: 🔥
4
- colorFrom: gray
5
- colorTo: red
6
  sdk: docker
7
  pinned: false
 
8
  ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ tags: [gradio-custom-component]
4
+ title: gradio_huggingfacehub_search V0.0.1
5
+ colorFrom: red
6
+ colorTo: gray
7
  sdk: docker
8
  pinned: false
9
+ license: apache-2.0
10
  ---
 
 
__init__.py ADDED
File without changes
__pycache__/__init__.cpython-310.pyc ADDED
Binary file (166 Bytes). View file
 
__pycache__/app.cpython-310.pyc ADDED
Binary file (922 Bytes). View file
 
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio_huggingfacehub_search import HuggingfaceHubSearch
3
+
4
+
5
+ example = HuggingfaceHubSearch().example_value()
6
+
7
+
8
+ def predict(hub_repo_id):
9
+ print("hub_repo_id", hub_repo_id)
10
+ return hub_repo_id
11
+
12
+
13
+ with gr.Blocks() as demo:
14
+ with gr.Row():
15
+ with gr.Column():
16
+ search_in = HuggingfaceHubSearch(
17
+ label="Search Huggingface Hub",
18
+ search_type=["model", "dataset"],
19
+ )
20
+ btn = gr.Button("Run")
21
+ with gr.Column():
22
+ search_out = HuggingfaceHubSearch(label="Search Huggingface Hub")
23
+ gr.on(
24
+ [btn.click, search_in.submit],
25
+ fn=predict,
26
+ inputs=[search_in],
27
+ outputs=[search_out],
28
+ )
29
+
30
+
31
+ if __name__ == "__main__":
32
+ demo.launch()
css.css ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ html {
2
+ font-family: Inter;
3
+ font-size: 16px;
4
+ font-weight: 400;
5
+ line-height: 1.5;
6
+ -webkit-text-size-adjust: 100%;
7
+ background: #fff;
8
+ color: #323232;
9
+ -webkit-font-smoothing: antialiased;
10
+ -moz-osx-font-smoothing: grayscale;
11
+ text-rendering: optimizeLegibility;
12
+ }
13
+
14
+ :root {
15
+ --space: 1;
16
+ --vspace: calc(var(--space) * 1rem);
17
+ --vspace-0: calc(3 * var(--space) * 1rem);
18
+ --vspace-1: calc(2 * var(--space) * 1rem);
19
+ --vspace-2: calc(1.5 * var(--space) * 1rem);
20
+ --vspace-3: calc(0.5 * var(--space) * 1rem);
21
+ }
22
+
23
+ .app {
24
+ max-width: 748px !important;
25
+ }
26
+
27
+ .prose p {
28
+ margin: var(--vspace) 0;
29
+ line-height: var(--vspace * 2);
30
+ font-size: 1rem;
31
+ }
32
+
33
+ code {
34
+ font-family: "Inconsolata", sans-serif;
35
+ font-size: 16px;
36
+ }
37
+
38
+ h1,
39
+ h1 code {
40
+ font-weight: 400;
41
+ line-height: calc(2.5 / var(--space) * var(--vspace));
42
+ }
43
+
44
+ h1 code {
45
+ background: none;
46
+ border: none;
47
+ letter-spacing: 0.05em;
48
+ padding-bottom: 5px;
49
+ position: relative;
50
+ padding: 0;
51
+ }
52
+
53
+ h2 {
54
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
55
+ line-height: 1em;
56
+ }
57
+
58
+ h3,
59
+ h3 code {
60
+ margin: var(--vspace-1) 0 var(--vspace-2) 0;
61
+ line-height: 1em;
62
+ }
63
+
64
+ h4,
65
+ h5,
66
+ h6 {
67
+ margin: var(--vspace-3) 0 var(--vspace-3) 0;
68
+ line-height: var(--vspace);
69
+ }
70
+
71
+ .bigtitle,
72
+ h1,
73
+ h1 code {
74
+ font-size: calc(8px * 4.5);
75
+ word-break: break-word;
76
+ }
77
+
78
+ .title,
79
+ h2,
80
+ h2 code {
81
+ font-size: calc(8px * 3.375);
82
+ font-weight: lighter;
83
+ word-break: break-word;
84
+ border: none;
85
+ background: none;
86
+ }
87
+
88
+ .subheading1,
89
+ h3,
90
+ h3 code {
91
+ font-size: calc(8px * 1.8);
92
+ font-weight: 600;
93
+ border: none;
94
+ background: none;
95
+ letter-spacing: 0.1em;
96
+ text-transform: uppercase;
97
+ }
98
+
99
+ h2 code {
100
+ padding: 0;
101
+ position: relative;
102
+ letter-spacing: 0.05em;
103
+ }
104
+
105
+ blockquote {
106
+ font-size: calc(8px * 1.1667);
107
+ font-style: italic;
108
+ line-height: calc(1.1667 * var(--vspace));
109
+ margin: var(--vspace-2) var(--vspace-2);
110
+ }
111
+
112
+ .subheading2,
113
+ h4 {
114
+ font-size: calc(8px * 1.4292);
115
+ text-transform: uppercase;
116
+ font-weight: 600;
117
+ }
118
+
119
+ .subheading3,
120
+ h5 {
121
+ font-size: calc(8px * 1.2917);
122
+ line-height: calc(1.2917 * var(--vspace));
123
+
124
+ font-weight: lighter;
125
+ text-transform: uppercase;
126
+ letter-spacing: 0.15em;
127
+ }
128
+
129
+ h6 {
130
+ font-size: calc(8px * 1.1667);
131
+ font-size: 1.1667em;
132
+ font-weight: normal;
133
+ font-style: italic;
134
+ font-family: "le-monde-livre-classic-byol", serif !important;
135
+ letter-spacing: 0px !important;
136
+ }
137
+
138
+ #start .md > *:first-child {
139
+ margin-top: 0;
140
+ }
141
+
142
+ h2 + h3 {
143
+ margin-top: 0;
144
+ }
145
+
146
+ .md hr {
147
+ border: none;
148
+ border-top: 1px solid var(--block-border-color);
149
+ margin: var(--vspace-2) 0 var(--vspace-2) 0;
150
+ }
151
+ .prose ul {
152
+ margin: var(--vspace-2) 0 var(--vspace-1) 0;
153
+ }
154
+
155
+ .gap {
156
+ gap: 0;
157
+ }
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio_huggingfacehub_search==0.0.1
space.py ADDED
@@ -0,0 +1,154 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import gradio as gr
3
+ from app import demo as app
4
+ import os
5
+
6
+ _docs = {'HuggingfaceHubSearch': {'description': 'Creates a very simple textbox for user to enter string input or display string output.', 'members': {'__init__': {'value': {'type': 'str | Callable | None', 'default': 'None', 'description': 'default text to provide in textbox. If callable, the function will be called whenever the app loads to set the initial value of the component.'}, 'placeholder': {'type': 'str | None', 'default': 'None', 'description': 'placeholder hint to provide behind textbox.'}, 'label': {'type': 'str | None', 'default': 'None', 'description': 'component name in interface.'}, 'every': {'type': 'float | None', 'default': 'None', 'description': "If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute."}, 'show_label': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will display label.'}, 'scale': {'type': 'int | None', 'default': 'None', 'description': 'relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.'}, 'min_width': {'type': 'int', 'default': '160', 'description': 'minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.'}, 'interactive': {'type': 'bool | None', 'default': 'None', 'description': 'if True, will be rendered as an editable textbox; if False, editing will be disabled. If not provided, this is inferred based on whether the component is used as an input or output.'}, 'visible': {'type': 'bool', 'default': 'True', 'description': 'If False, component will be hidden.'}, 'rtl': {'type': 'bool', 'default': 'False', 'description': 'If True and `type` is "text", sets the direction of the text to right-to-left (cursor appears on the left of the text). Default is False, which renders cursor on the right.'}, 'elem_id': {'type': 'str | None', 'default': 'None', 'description': 'An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'elem_classes': {'type': 'list[str] | str | None', 'default': 'None', 'description': 'An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.'}, 'render': {'type': 'bool', 'default': 'True', 'description': 'If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.'}, 'search_type': {'type': 'str | list[str] | None', 'default': 'None', 'description': 'Type of search you want to enable your quicksearch "model", "dataset","space","org", "user" or a list of these.'}, 'sumbit_on_select': {'type': 'bool', 'default': 'True', 'description': 'If true, the component will submit when the user selects a value from the dropdown.'}}, 'postprocess': {'value': {'type': 'str | None', 'description': 'Expects a {str} returned from function and sets textarea value to it.'}}, 'preprocess': {'return': {'type': 'str | None', 'description': 'Passes text value as a {str} into the function.'}, 'value': None}}, 'events': {'change': {'type': None, 'default': None, 'description': 'Triggered when the value of the HuggingfaceHubSearch changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See `.input()` for a listener that is only triggered by user input.'}, 'input': {'type': None, 'default': None, 'description': 'This listener is triggered when the user changes the value of the HuggingfaceHubSearch.'}, 'submit': {'type': None, 'default': None, 'description': 'This listener is triggered when the user presses the Enter key while the HuggingfaceHubSearch is focused.'}}}, '__meta__': {'additional_interfaces': {}, 'user_fn_refs': {'HuggingfaceHubSearch': []}}}
7
+
8
+ abs_path = os.path.join(os.path.dirname(__file__), "css.css")
9
+
10
+ with gr.Blocks(
11
+ css=abs_path,
12
+ theme=gr.themes.Default(
13
+ font_mono=[
14
+ gr.themes.GoogleFont("Inconsolata"),
15
+ "monospace",
16
+ ],
17
+ ),
18
+ ) as demo:
19
+ gr.Markdown(
20
+ """
21
+ # `gradio_huggingfacehub_search`
22
+
23
+ <div style="display: flex; gap: 7px;">
24
+ <img alt="Static Badge" src="https://img.shields.io/badge/version%20-%200.0.1%20-%20orange">
25
+ </div>
26
+
27
+ Gradio component for searching Hugging Face Hub models, datasets, Spaces, and more
28
+ """, elem_classes=["md-custom"], header_links=True)
29
+ app.render()
30
+ gr.Markdown(
31
+ """
32
+ ## Installation
33
+
34
+ ```bash
35
+ pip install gradio_huggingfacehub_search
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ ```python
41
+ import gradio as gr
42
+ from gradio_huggingfacehub_search import HuggingfaceHubSearch
43
+
44
+
45
+ example = HuggingfaceHubSearch().example_value()
46
+
47
+
48
+ def predict(hub_repo_id):
49
+ print("hub_repo_id", hub_repo_id)
50
+ return hub_repo_id
51
+
52
+
53
+ with gr.Blocks() as demo:
54
+ with gr.Row():
55
+ with gr.Column():
56
+ search_in = HuggingfaceHubSearch(
57
+ label="Search Huggingface Hub",
58
+ search_type=["model", "dataset"],
59
+ )
60
+ btn = gr.Button("Run")
61
+ with gr.Column():
62
+ search_out = HuggingfaceHubSearch(label="Search Huggingface Hub")
63
+ gr.on(
64
+ [btn.click, search_in.submit],
65
+ fn=predict,
66
+ inputs=[search_in],
67
+ outputs=[search_out],
68
+ )
69
+
70
+
71
+ if __name__ == "__main__":
72
+ demo.launch()
73
+
74
+ ```
75
+ """, elem_classes=["md-custom"], header_links=True)
76
+
77
+
78
+ gr.Markdown("""
79
+ ## `HuggingfaceHubSearch`
80
+
81
+ ### Initialization
82
+ """, elem_classes=["md-custom"], header_links=True)
83
+
84
+ gr.ParamViewer(value=_docs["HuggingfaceHubSearch"]["members"]["__init__"], linkify=[])
85
+
86
+
87
+ gr.Markdown("### Events")
88
+ gr.ParamViewer(value=_docs["HuggingfaceHubSearch"]["events"], linkify=['Event'])
89
+
90
+
91
+
92
+
93
+ gr.Markdown("""
94
+
95
+ ### User function
96
+
97
+ The impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).
98
+
99
+ - When used as an Input, the component only impacts the input signature of the user function.
100
+ - When used as an output, the component only impacts the return signature of the user function.
101
+
102
+ The code snippet below is accurate in cases where the component is used as both an input and an output.
103
+
104
+ - **As input:** Is passed, passes text value as a {str} into the function.
105
+ - **As output:** Should return, expects a {str} returned from function and sets textarea value to it.
106
+
107
+ ```python
108
+ def predict(
109
+ value: str | None
110
+ ) -> str | None:
111
+ return value
112
+ ```
113
+ """, elem_classes=["md-custom", "HuggingfaceHubSearch-user-fn"], header_links=True)
114
+
115
+
116
+
117
+
118
+ demo.load(None, js=r"""function() {
119
+ const refs = {};
120
+ const user_fn_refs = {
121
+ HuggingfaceHubSearch: [], };
122
+ requestAnimationFrame(() => {
123
+
124
+ Object.entries(user_fn_refs).forEach(([key, refs]) => {
125
+ if (refs.length > 0) {
126
+ const el = document.querySelector(`.${key}-user-fn`);
127
+ if (!el) return;
128
+ refs.forEach(ref => {
129
+ el.innerHTML = el.innerHTML.replace(
130
+ new RegExp("\\b"+ref+"\\b", "g"),
131
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
132
+ );
133
+ })
134
+ }
135
+ })
136
+
137
+ Object.entries(refs).forEach(([key, refs]) => {
138
+ if (refs.length > 0) {
139
+ const el = document.querySelector(`.${key}`);
140
+ if (!el) return;
141
+ refs.forEach(ref => {
142
+ el.innerHTML = el.innerHTML.replace(
143
+ new RegExp("\\b"+ref+"\\b", "g"),
144
+ `<a href="#h-${ref.toLowerCase()}">${ref}</a>`
145
+ );
146
+ })
147
+ }
148
+ })
149
+ })
150
+ }
151
+
152
+ """)
153
+
154
+ demo.launch()