Spaces:
Configuration error
Configuration error
LucaVivona
commited on
Commit
β’
8a8c958
1
Parent(s):
cbe21a9
more updates π§βππ
Browse files- README.md +20 -9
- backend/src/demo/demo.py +46 -0
- backend/src/demoC.py +0 -22
- backend/src/demoE.py +0 -3
- backend/src/demoF.py +0 -20
- backend/src/demoL.py +0 -8
- backend/src/resources/__pycache__/module.cpython-39.pyc +0 -0
- backend/src/resources/module.py +18 -18
- frontend/public/index.html +3 -0
- frontend/src/Components/Nodes/custom.js +0 -2
README.md
CHANGED
@@ -136,8 +136,8 @@ Now that you're within the docker backend container environment you can start ad
|
|
136 |
#### **3.** Appending Nodes To Frontend From The Backend
|
137 |
|
138 |
```console
|
139 |
-
> cd ./src
|
140 |
-
> python
|
141 |
//run example gradio application
|
142 |
```
|
143 |
|
@@ -169,13 +169,13 @@ It is quite simple, and similar within the docker build, the first way you can a
|
|
169 |
**NOTE** If you use the gradio decorator compiler for gradio flow you need to set a listen port to 2000 or else the api will never get the key and will throw you an error, I'll also provided an example below if this isn't clear.
|
170 |
|
171 |
```python
|
172 |
-
#
|
173 |
##########
|
174 |
from resources import register, tabularGradio
|
175 |
|
176 |
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
177 |
def Hello_World(name):
|
178 |
-
return f"Hello {name}, and welcome to Gradio Flow π€"
|
179 |
|
180 |
@register(inputs=["number", "number"], outputs=["number"], examples=[[1,1]])
|
181 |
def add(x, y):
|
@@ -183,15 +183,15 @@ def add(x, y):
|
|
183 |
|
184 |
if __name__ == "__main__":
|
185 |
# run single gradio
|
186 |
-
tabularGradio([Hello_World(
|
187 |
|
188 |
# run it within Gradio-Flow
|
189 |
-
# tabularGradio([Hello_World(
|
190 |
|
191 |
```
|
192 |
|
193 |
```python
|
194 |
-
#
|
195 |
###########
|
196 |
from resources import GradioModule, register
|
197 |
|
@@ -200,7 +200,7 @@ class Greeting:
|
|
200 |
|
201 |
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
202 |
def Hello_World(self, name):
|
203 |
-
return f"Hello {name}, and welcome to Gradio Flow π€"
|
204 |
|
205 |
@register(inputs=["number", "number"], outputs=["number"], examples=[[1,1]])
|
206 |
def add(self, x, y):
|
@@ -212,7 +212,18 @@ if __name__ == "__main__":
|
|
212 |
Greeting().launch()
|
213 |
# run it within Gradio-flow
|
214 |
# Greeting().launch(listen=2000)
|
215 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
216 |
## Application ποΈ
|
217 |
![Dark-Application](https://github.com/LVivona/Gradio-Flow/blob/8edde72f878c174f53602c4ddff0fc6d3fc7cd61/images/app.png)
|
218 |
![Light-Application](https://github.com/LVivona/Gradio-Flow/blob/8edde72f878c174f53602c4ddff0fc6d3fc7cd61/images/light-app.png)
|
|
|
136 |
#### **3.** Appending Nodes To Frontend From The Backend
|
137 |
|
138 |
```console
|
139 |
+
> cd ./src/demo
|
140 |
+
> python demo.py -l 2000
|
141 |
//run example gradio application
|
142 |
```
|
143 |
|
|
|
169 |
**NOTE** If you use the gradio decorator compiler for gradio flow you need to set a listen port to 2000 or else the api will never get the key and will throw you an error, I'll also provided an example below if this isn't clear.
|
170 |
|
171 |
```python
|
172 |
+
# (functional base)
|
173 |
##########
|
174 |
from resources import register, tabularGradio
|
175 |
|
176 |
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
177 |
def Hello_World(name):
|
178 |
+
return f"π Hello {name}, and welcome to Gradio Flow π€"
|
179 |
|
180 |
@register(inputs=["number", "number"], outputs=["number"], examples=[[1,1]])
|
181 |
def add(x, y):
|
|
|
183 |
|
184 |
if __name__ == "__main__":
|
185 |
# run single gradio
|
186 |
+
tabularGradio([Hello_World, add]) # tabularGradio([Hello_World, add], ["Hello World", "Add"])
|
187 |
|
188 |
# run it within Gradio-Flow
|
189 |
+
# tabularGradio([Hello_World, add], ["Hello World", "Add"], listen=2000) # tabularGradio([Hello_World, add], ["Hello World", "Add"], listen=2000)
|
190 |
|
191 |
```
|
192 |
|
193 |
```python
|
194 |
+
#(Class Base)
|
195 |
###########
|
196 |
from resources import GradioModule, register
|
197 |
|
|
|
200 |
|
201 |
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
202 |
def Hello_World(self, name):
|
203 |
+
return f"π Hello {name}, and welcome to Gradio Flow π€"
|
204 |
|
205 |
@register(inputs=["number", "number"], outputs=["number"], examples=[[1,1]])
|
206 |
def add(self, x, y):
|
|
|
212 |
Greeting().launch()
|
213 |
# run it within Gradio-flow
|
214 |
# Greeting().launch(listen=2000)
|
215 |
+
```
|
216 |
+
|
217 |
+
# More Demos β
|
218 |
+
Within the ``backend/src/demo`` directory there are some demos
|
219 |
+
```command
|
220 |
+
# type : class | function | load | None
|
221 |
+
# port : 2000 | None
|
222 |
+
# python demo.py -e [type] -l [port]
|
223 |
+
(e.g)
|
224 |
+
> python demo.py -e class -l 2000
|
225 |
+
> python demo.py -e class
|
226 |
+
```
|
227 |
## Application ποΈ
|
228 |
![Dark-Application](https://github.com/LVivona/Gradio-Flow/blob/8edde72f878c174f53602c4ddff0fc6d3fc7cd61/images/app.png)
|
229 |
![Light-Application](https://github.com/LVivona/Gradio-Flow/blob/8edde72f878c174f53602c4ddff0fc6d3fc7cd61/images/light-app.png)
|
backend/src/demo/demo.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import argparse
|
2 |
+
import sys
|
3 |
+
|
4 |
+
sys.path.insert(0, "../")
|
5 |
+
from resources import GradioModule, register, InterLauncher, tabularGradio
|
6 |
+
from example.examples import Pictionary
|
7 |
+
|
8 |
+
import gradio as gr
|
9 |
+
|
10 |
+
parser = argparse.ArgumentParser()
|
11 |
+
parser.add_argument("-e", "--examples", help="Examples made to show how to append it your own functon or classes", default="")
|
12 |
+
parser.add_argument("-l", "--listen", help="send the gradio information to flask api **NOTE error will show up if the api is not up", default=None)
|
13 |
+
args = parser.parse_args()
|
14 |
+
gr.close_all()
|
15 |
+
if args.examples == "class":
|
16 |
+
@GradioModule
|
17 |
+
class Greeting:
|
18 |
+
|
19 |
+
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
20 |
+
def Hello_World(self, name):
|
21 |
+
return f"π Hello {name}, and welcome to Gradio Flow π€"
|
22 |
+
|
23 |
+
@register(["number", "number"], ["number"], examples=[[1,1]])
|
24 |
+
def add(self, x, y):
|
25 |
+
return x + y
|
26 |
+
|
27 |
+
Greeting().launch() if args.listen == None else Greeting().launch(listen=args.listen)
|
28 |
+
|
29 |
+
elif args.examples == "function":
|
30 |
+
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
31 |
+
def Hello_World(name):
|
32 |
+
return f"π Hello {name}, and welcome to Gradio Flow π€"
|
33 |
+
|
34 |
+
@register(["number", "number"], ["number"], examples=[[1,1]])
|
35 |
+
def add(x, y):
|
36 |
+
return x + y
|
37 |
+
tabularGradio([Hello_World, add]) if args.listen == None else tabularGradio([Hello_World, add], listen=args.listen)
|
38 |
+
|
39 |
+
elif args.examples == "load":
|
40 |
+
description = "Story generation with GPT"
|
41 |
+
examples = [["An adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
|
42 |
+
demo = gr.Interface.load("models/EleutherAI/gpt-neo-1.3B", description=description, examples=examples)
|
43 |
+
InterLauncher("Demo", demo) if args.listen == None else InterLauncher("Demo", demo, listen=args.listen)
|
44 |
+
|
45 |
+
else:
|
46 |
+
Pictionary("../example/data/labels.txt", "../example/data/pytorch_model.bin").launch(live=True) if args.listen == None else Pictionary("../example/data/labels.txt", "../example/data/pytorch_model.bin").launch(live=True, listen=args.listen)
|
backend/src/demoC.py
DELETED
@@ -1,22 +0,0 @@
|
|
1 |
-
from resources import GradioModule, register, InterLauncher
|
2 |
-
import gradio as gr
|
3 |
-
|
4 |
-
@GradioModule
|
5 |
-
class Greeting:
|
6 |
-
|
7 |
-
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
8 |
-
def Hello_World(self, name):
|
9 |
-
return f"Hello {name}, and welcome to Gradio Flow π€"
|
10 |
-
|
11 |
-
@register(["number", "number"], ["number"], examples=[[1,1]])
|
12 |
-
def add(self, x, y):
|
13 |
-
return x + y
|
14 |
-
|
15 |
-
|
16 |
-
if __name__ == "__main__":
|
17 |
-
# run just gradio
|
18 |
-
# Greeting().launch()
|
19 |
-
# run it within Gradio-flow
|
20 |
-
Greeting().launch(listen=2000)
|
21 |
-
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/src/demoE.py
DELETED
@@ -1,3 +0,0 @@
|
|
1 |
-
from example.examples import Pictionary, FSD, HelloWorld_2_0, stock_forecast
|
2 |
-
|
3 |
-
Pictionary("./example/data/labels.txt", "./example/data/pytorch_model.bin").launch(live=True, listen=2000)
|
|
|
|
|
|
|
|
backend/src/demoF.py
DELETED
@@ -1,20 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
from resources import register, tabularGradio
|
3 |
-
from example.examples import FSD, Pictionary
|
4 |
-
|
5 |
-
@register(["text"], ["text"], examples=[["Luca Vivona"]])
|
6 |
-
def Hello_World(name):
|
7 |
-
return f"Hello {name}, and welcome to Gradio Flow π€"
|
8 |
-
|
9 |
-
@register(["number", "number"], ["number"], examples=[[1,1]])
|
10 |
-
def add(x, y):
|
11 |
-
return x + y
|
12 |
-
|
13 |
-
if __name__ == "__main__":
|
14 |
-
# run single gradio
|
15 |
-
|
16 |
-
tabularGradio([Hello_World(), add()], ["Hello World", "Add"])
|
17 |
-
|
18 |
-
# run it within Gradio-Flow
|
19 |
-
# tabularGradio([Hello_World(), add()], ["Hello World", "Add"], listen=2000)
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/src/demoL.py
DELETED
@@ -1,8 +0,0 @@
|
|
1 |
-
from resources import GradioModule, register, InterLauncher
|
2 |
-
import gradio as gr
|
3 |
-
|
4 |
-
if __name__ == "__main__":
|
5 |
-
description = "Story generation with GPT"
|
6 |
-
examples = [["An adventurer is approached by a mysterious stranger in the tavern for a new quest."]]
|
7 |
-
demo = gr.Interface.load("models/EleutherAI/gpt-neo-1.3B", description=description, examples=examples)
|
8 |
-
InterLauncher("Demo", demo, listen=2000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/src/resources/__pycache__/module.cpython-39.pyc
CHANGED
Binary files a/backend/src/resources/__pycache__/module.cpython-39.pyc and b/backend/src/resources/__pycache__/module.cpython-39.pyc differ
|
|
backend/src/resources/module.py
CHANGED
@@ -1,15 +1,16 @@
|
|
1 |
import gradio as gr
|
2 |
-
from inspect import getfile
|
3 |
|
4 |
import socket
|
5 |
-
import random
|
6 |
import requests
|
7 |
|
8 |
class Dock:
|
9 |
|
10 |
def __init__(self) -> None:
|
11 |
-
self.
|
12 |
-
|
|
|
|
|
13 |
|
14 |
def portConnection(self, port : int):
|
15 |
s = socket.socket(
|
@@ -18,15 +19,11 @@ class Dock:
|
|
18 |
if result == 0: return True
|
19 |
return False
|
20 |
|
21 |
-
def determinePort(self
|
22 |
-
|
23 |
-
|
24 |
-
port
|
25 |
-
|
26 |
-
return port
|
27 |
-
trial_count += 1
|
28 |
-
raise Exception('Exceeded Max Trial count without finding port')
|
29 |
-
|
30 |
|
31 |
DOCKER_LOCAL_HOST = '0.0.0.0'
|
32 |
DOCKER_PORT = Dock()
|
@@ -41,7 +38,7 @@ def InterLauncher(name, interface, listen=2000, **kwargs):
|
|
41 |
|
42 |
interface.launch(server_port=port,
|
43 |
server_name=f"{DOCKER_LOCAL_HOST}",
|
44 |
-
inline= kwargs['inline'] if "inline" in kwargs else
|
45 |
share=kwargs['share'] if "share" in kwargs else None,
|
46 |
debug=kwargs['debug'] if "debug" in kwargs else False,
|
47 |
enable_queue=kwargs['enable_queue'] if "enable_queue" in kwargs else None,
|
@@ -65,13 +62,16 @@ def InterLauncher(name, interface, listen=2000, **kwargs):
|
|
65 |
except Exception as e:
|
66 |
print(f"**{bcolor.BOLD}{bcolor.FAIL}CONNECTION ERROR{bcolor.ENDC}** πThe api either lost connection or was turned off...π \n {e}")
|
67 |
|
68 |
-
def tabularGradio(funcs, names, name="Tabular Temp Name", **kwargs):
|
69 |
"""
|
70 |
takes all gradio Interfaces, and names
|
71 |
from input and launch the gradio.
|
72 |
"""
|
73 |
|
74 |
-
|
|
|
|
|
|
|
75 |
port= kwargs["port"] if "port" in kwargs else DOCKER_PORT.determinePort()
|
76 |
|
77 |
# send this to the backend api for it to be read by the react frontend
|
@@ -83,7 +83,7 @@ def tabularGradio(funcs, names, name="Tabular Temp Name", **kwargs):
|
|
83 |
return
|
84 |
|
85 |
# provided by gradio a tabularInterface function that take function and names
|
86 |
-
gr.TabbedInterface(
|
87 |
server_name=f"{DOCKER_LOCAL_HOST}",
|
88 |
inline= kwargs['inline'] if "inline" in kwargs else True,
|
89 |
share=kwargs['share'] if "share" in kwargs else None,
|
@@ -154,7 +154,7 @@ def register(inputs, outputs, examples=None, **kwargs):
|
|
154 |
css=kwargs['css'] if "css" in kwargs else None,
|
155 |
live=kwargs['live'] if "live" in kwargs else False,
|
156 |
allow_flagging=kwargs['allow_flagging'] if "allow_flagging" in kwargs else None,
|
157 |
-
theme=kwargs['theme'] if "theme" in kwargs else
|
158 |
|
159 |
if len(args[1:]) == (func.__code__.co_argcount - 1):
|
160 |
return func(*args, **wargs)
|
|
|
1 |
import gradio as gr
|
2 |
+
from inspect import getfile
|
3 |
|
4 |
import socket
|
|
|
5 |
import requests
|
6 |
|
7 |
class Dock:
|
8 |
|
9 |
def __init__(self) -> None:
|
10 |
+
self.port_map = dict()
|
11 |
+
for p in range(7860, 7880):
|
12 |
+
if not self.portConnection(p):
|
13 |
+
self.port_map[p] = True
|
14 |
|
15 |
def portConnection(self, port : int):
|
16 |
s = socket.socket(
|
|
|
19 |
if result == 0: return True
|
20 |
return False
|
21 |
|
22 |
+
def determinePort(self):
|
23 |
+
for port, available in self.port_map.items():
|
24 |
+
if available == True:
|
25 |
+
return port
|
26 |
+
raise Exception(f'β π {bcolor.BOLD}{bcolor.UNDERLINE}{bcolor.FAIL}All visable ports are used up...Try close some ports {bcolor.ENDC}')
|
|
|
|
|
|
|
|
|
27 |
|
28 |
DOCKER_LOCAL_HOST = '0.0.0.0'
|
29 |
DOCKER_PORT = Dock()
|
|
|
38 |
|
39 |
interface.launch(server_port=port,
|
40 |
server_name=f"{DOCKER_LOCAL_HOST}",
|
41 |
+
inline= kwargs['inline'] if "inline" in kwargs else False,
|
42 |
share=kwargs['share'] if "share" in kwargs else None,
|
43 |
debug=kwargs['debug'] if "debug" in kwargs else False,
|
44 |
enable_queue=kwargs['enable_queue'] if "enable_queue" in kwargs else None,
|
|
|
62 |
except Exception as e:
|
63 |
print(f"**{bcolor.BOLD}{bcolor.FAIL}CONNECTION ERROR{bcolor.ENDC}** πThe api either lost connection or was turned off...π \n {e}")
|
64 |
|
65 |
+
def tabularGradio(funcs, names=[], name="Tabular Temp Name", **kwargs):
|
66 |
"""
|
67 |
takes all gradio Interfaces, and names
|
68 |
from input and launch the gradio.
|
69 |
"""
|
70 |
|
71 |
+
fn = [fn() for fn in funcs if not isinstance(fn, gr.Interface) and fn.__decorator__ == "__gradio__" ]
|
72 |
+
if len(names) == 0:
|
73 |
+
names = [_.__name__ for _ in fn]
|
74 |
+
|
75 |
port= kwargs["port"] if "port" in kwargs else DOCKER_PORT.determinePort()
|
76 |
|
77 |
# send this to the backend api for it to be read by the react frontend
|
|
|
83 |
return
|
84 |
|
85 |
# provided by gradio a tabularInterface function that take function and names
|
86 |
+
gr.TabbedInterface(fn, names).launch(server_port=port,
|
87 |
server_name=f"{DOCKER_LOCAL_HOST}",
|
88 |
inline= kwargs['inline'] if "inline" in kwargs else True,
|
89 |
share=kwargs['share'] if "share" in kwargs else None,
|
|
|
154 |
css=kwargs['css'] if "css" in kwargs else None,
|
155 |
live=kwargs['live'] if "live" in kwargs else False,
|
156 |
allow_flagging=kwargs['allow_flagging'] if "allow_flagging" in kwargs else None,
|
157 |
+
theme=kwargs['theme'] if "theme" in kwargs else 'default', )
|
158 |
|
159 |
if len(args[1:]) == (func.__code__.co_argcount - 1):
|
160 |
return func(*args, **wargs)
|
frontend/public/index.html
CHANGED
@@ -31,6 +31,9 @@
|
|
31 |
href="https://cdn.jsdelivr.net/npm/semantic-ui@2/dist/semantic.min.css"
|
32 |
/>
|
33 |
<script src="https://cdn.jsdelivr.net/npm/semantic-ui-react/dist/umd/semantic-ui-react.min.js"></script>
|
|
|
|
|
|
|
34 |
|
35 |
</head>
|
36 |
<body>
|
|
|
31 |
href="https://cdn.jsdelivr.net/npm/semantic-ui@2/dist/semantic.min.css"
|
32 |
/>
|
33 |
<script src="https://cdn.jsdelivr.net/npm/semantic-ui-react/dist/umd/semantic-ui-react.min.js"></script>
|
34 |
+
<script type="module"
|
35 |
+
src="https://gradio.s3-us-west-2.amazonaws.com/3.1.1/gradio.js">
|
36 |
+
</script>
|
37 |
|
38 |
</head>
|
39 |
<body>
|
frontend/src/Components/Nodes/custom.js
CHANGED
@@ -34,8 +34,6 @@ import React from "react"
|
|
34 |
src={this.state.data.host}
|
35 |
title={this.state.data.label}
|
36 |
frameBorder="0" class="container h-full p-2 flex-grow space-iframe overflow-scroll " allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"></iframe>
|
37 |
-
{/* {console.log(this.myRef.current.contentWindow)} */}
|
38 |
-
{/* <gradio-app space={`${this.state.data.host}/api/predict`} className="w-full h-full"></gradio-app> */}
|
39 |
</div>:
|
40 |
<>
|
41 |
<div className='break-words'>
|
|
|
34 |
src={this.state.data.host}
|
35 |
title={this.state.data.label}
|
36 |
frameBorder="0" class="container h-full p-2 flex-grow space-iframe overflow-scroll " allow="accelerometer; ambient-light-sensor; autoplay; battery; camera; document-domain; encrypted-media; fullscreen; geolocation; gyroscope; layout-animations; legacy-image-formats; magnetometer; microphone; midi; oversized-images; payment; picture-in-picture; publickey-credentials-get; sync-xhr; usb; vr ; wake-lock; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-downloads"></iframe>
|
|
|
|
|
37 |
</div>:
|
38 |
<>
|
39 |
<div className='break-words'>
|