Spaces:
Configuration error
Configuration error
Commit
Β·
5bcb90a
1
Parent(s):
e8007d5
refactor π»
Browse files- backend/src/__init__.py +1 -2
- backend/src/__pycache__/__init__.cpython-39.pyc +0 -0
- backend/src/__pycache__/demo.cpython-39.pyc +0 -0
- backend/src/demo.py +2 -2
- backend/src/example/__init__.py +1 -0
- backend/src/index.py +4 -8
- backend/src/resources/__pycache__/module.cpython-39.pyc +0 -0
- backend/src/resources/dock.py +0 -24
- backend/src/resources/module.py +5 -2
- backend/test/test.py +39 -0
backend/src/__init__.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import
|
2 |
-
from .example.examples import *
|
3 |
import src.demo
|
4 |
import src.index
|
|
|
1 |
+
import resource
|
|
|
2 |
import src.demo
|
3 |
import src.index
|
backend/src/__pycache__/__init__.cpython-39.pyc
ADDED
Binary file (254 Bytes). View file
|
|
backend/src/__pycache__/demo.cpython-39.pyc
ADDED
Binary file (701 Bytes). View file
|
|
backend/src/demo.py
CHANGED
@@ -5,9 +5,9 @@ from resources import register, tabularGradio
|
|
5 |
def Hello_World(name):
|
6 |
return f"Hello {name}, and welcome to Gradio Flow π€"
|
7 |
|
8 |
-
@register(["number"], ["number"], examples=[[1,1]])
|
9 |
def add(x, y):
|
10 |
return x + y
|
11 |
|
12 |
if __name__ == "__main__":
|
13 |
-
tabularGradio([Hello_World()], ["Hello World"])
|
|
|
5 |
def Hello_World(name):
|
6 |
return f"Hello {name}, and welcome to Gradio Flow π€"
|
7 |
|
8 |
+
@register(["number", "number"], ["number"], examples=[[1,1]])
|
9 |
def add(x, y):
|
10 |
return x + y
|
11 |
|
12 |
if __name__ == "__main__":
|
13 |
+
tabularGradio([Hello_World(), add()], ["Hello World",])
|
backend/src/example/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
from .examples import *
|
backend/src/index.py
CHANGED
@@ -1,5 +1,4 @@
|
|
1 |
from resources import GradioModule, register
|
2 |
-
import gradio as gr
|
3 |
|
4 |
@GradioModule
|
5 |
class Greeting:
|
@@ -8,12 +7,9 @@ class Greeting:
|
|
8 |
def Hello_World(self, name):
|
9 |
return f"Hello {name}, and welcome to Gradio Flow π€"
|
10 |
|
11 |
-
@register(["
|
12 |
-
def
|
13 |
-
|
14 |
-
|
15 |
|
16 |
if __name__ == "__main__":
|
17 |
-
|
18 |
-
|
19 |
-
# Greeting().run(listen=2000)
|
|
|
1 |
from resources import GradioModule, register
|
|
|
2 |
|
3 |
@GradioModule
|
4 |
class Greeting:
|
|
|
7 |
def Hello_World(self, name):
|
8 |
return f"Hello {name}, and welcome to Gradio Flow π€"
|
9 |
|
10 |
+
@register(["number", "number"], ["number"], examples=[[1,1]])
|
11 |
+
def add(self, x, y):
|
12 |
+
return x + y
|
|
|
13 |
|
14 |
if __name__ == "__main__":
|
15 |
+
Greeting().run(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/dock.py
DELETED
@@ -1,24 +0,0 @@
|
|
1 |
-
import socket
|
2 |
-
import random
|
3 |
-
|
4 |
-
class Dock:
|
5 |
-
|
6 |
-
def __init__(self) -> None:
|
7 |
-
self.num_ports = 20
|
8 |
-
self.port_range = (7860, 7880)
|
9 |
-
|
10 |
-
def portConnection(self, port : int):
|
11 |
-
s = socket.socket(
|
12 |
-
socket.AF_INET, socket.SOCK_STREAM)
|
13 |
-
result = s.connect_ex(("localhost", port))
|
14 |
-
if result == 0: return True
|
15 |
-
return False
|
16 |
-
|
17 |
-
def determinePort(self, max_trial_count=10):
|
18 |
-
trial_count = 0
|
19 |
-
while trial_count <= max_trial_count:
|
20 |
-
port=random.randint(*self.port_range)
|
21 |
-
if not self.portConnection(port):
|
22 |
-
return port
|
23 |
-
trial_count += 1
|
24 |
-
raise Exception('Exceeded Max Trial count without finding port')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
backend/src/resources/module.py
CHANGED
@@ -32,6 +32,9 @@ DOCKER_LOCAL_HOST = '0.0.0.0'
|
|
32 |
DOCKER_PORT = Dock()
|
33 |
|
34 |
def tabularGradio(funcs, names, name="Tabular Temp Name", **kwargs):
|
|
|
|
|
|
|
35 |
port= kwargs["port"] if "port" in kwargs else DOCKER_PORT.determinePort()
|
36 |
|
37 |
try:
|
@@ -82,7 +85,7 @@ def register(inputs, outputs, examples=None, **kwargs):
|
|
82 |
initialize a registered_gradio_functons
|
83 |
if not already initialize.
|
84 |
"""
|
85 |
-
assert len(inputs) == func.__code__.co_argcount - 1, "β inputs should have the same length as arguments"
|
86 |
|
87 |
try:
|
88 |
self = args[0]
|
@@ -102,7 +105,7 @@ def register(inputs, outputs, examples=None, **kwargs):
|
|
102 |
"""
|
103 |
the function is not a class function
|
104 |
"""
|
105 |
-
assert len(inputs) == func.__code__.co_argcount, "β inputs should have the same length as arguments"
|
106 |
|
107 |
if len(args) == (func.__code__.co_argcount):
|
108 |
return func(*args, **wargs)
|
|
|
32 |
DOCKER_PORT = Dock()
|
33 |
|
34 |
def tabularGradio(funcs, names, name="Tabular Temp Name", **kwargs):
|
35 |
+
#print([fn.__name__ for fn in funcs])
|
36 |
+
assert len(funcs) == len(names), f"{bcolor.BOLD}{bcolor.FAIL}π something went wrong!!! The function you appended dose not match the lenght of the names{bcolor.ENDC}"
|
37 |
+
# assert all([fn == "wrap" for fn in funcs]), f"{bcolor().BOLD}{bcolor().FAIL}not all of these are decorated with the right decorator{bcolor().ENDC}"
|
38 |
port= kwargs["port"] if "port" in kwargs else DOCKER_PORT.determinePort()
|
39 |
|
40 |
try:
|
|
|
85 |
initialize a registered_gradio_functons
|
86 |
if not already initialize.
|
87 |
"""
|
88 |
+
assert len(inputs) == func.__code__.co_argcount - 1, f"β {bcolor.BOLD}{bcolor.FAIL}inputs should have the same length as arguments{bcolor.ENDC}"
|
89 |
|
90 |
try:
|
91 |
self = args[0]
|
|
|
105 |
"""
|
106 |
the function is not a class function
|
107 |
"""
|
108 |
+
assert len(inputs) == func.__code__.co_argcount, f"β {bcolor.BOLD}{bcolor.FAIL}inputs should have the same length as arguments{bcolor.ENDC}"
|
109 |
|
110 |
if len(args) == (func.__code__.co_argcount):
|
111 |
return func(*args, **wargs)
|
backend/test/test.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import unittest
|
2 |
+
import sys
|
3 |
+
sys.path.insert(0, "../src/resources")
|
4 |
+
from module import GradioModule, register
|
5 |
+
|
6 |
+
@GradioModule
|
7 |
+
class test:
|
8 |
+
@register(inputs=["text"], outputs=["text"])
|
9 |
+
def Hello(self, name):
|
10 |
+
return f"Hello, {name}."
|
11 |
+
|
12 |
+
@register(inputs=["text"], outputs=["text"])
|
13 |
+
def Goodbye(self, name):
|
14 |
+
return f"Goodbye, {name}."
|
15 |
+
|
16 |
+
@register(inputs=["text"], outputs=["text"])
|
17 |
+
def Hello(name):
|
18 |
+
return f"Hello, {name}."
|
19 |
+
|
20 |
+
@register(inputs=["text"], outputs=["text"])
|
21 |
+
def Goodbye(name):
|
22 |
+
return f"Goodbye, {name}."
|
23 |
+
|
24 |
+
class GradioFlowTestCase(unittest.TestCase):
|
25 |
+
cls = test()
|
26 |
+
def test_class_func_return(self):
|
27 |
+
self.assertEqual(self.cls.cls.Hello("Luca"), "Hello, Luca.")
|
28 |
+
self.assertEqual(self.cls.cls.Goodbye("Luca"), "Goodbye, Luca.")
|
29 |
+
|
30 |
+
|
31 |
+
def test_func_return(self):
|
32 |
+
self.assertEqual(Hello("Luca"), "Hello, Luca.")
|
33 |
+
self.assertEqual(Goodbye("Luca"), "Goodbye, Luca.")
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
unittest.main()
|