Spaces:
Configuration error
Configuration error
Luca Vivona
commited on
Commit
·
7a0af64
1
Parent(s):
f670280
⚙️ updated examples
Browse files
backend/src/example/examples.py
CHANGED
@@ -1,14 +1,15 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
import matplotlib
|
3 |
import matplotlib.pyplot as plt
|
4 |
import numpy as np
|
5 |
import PIL
|
6 |
-
from helper.compiler import GradioCompiler, register
|
7 |
-
|
8 |
|
|
|
|
|
9 |
|
10 |
"""
|
11 |
-
@
|
12 |
class Pictionary:
|
13 |
|
14 |
def __init__(self) -> None:
|
@@ -45,7 +46,7 @@ class Pictionary:
|
|
45 |
return confidences
|
46 |
"""
|
47 |
|
48 |
-
@
|
49 |
class HelloWorld_2_0:
|
50 |
|
51 |
@register(inputs=["text", "text", gr.Radio(["morning", "evening", "night"])], outputs="text")
|
@@ -65,7 +66,7 @@ class HelloWorld_2_0:
|
|
65 |
|
66 |
|
67 |
|
68 |
-
@
|
69 |
class FSD:
|
70 |
|
71 |
def get_new_val(self, old_val, nc):
|
@@ -100,9 +101,29 @@ class FSD:
|
|
100 |
carr = np.array(pixels / np.max(pixels, axis=(0, 1)) * 255, dtype=np.uint8)
|
101 |
return [PIL.Image.fromarray(carr), self.palette_reduce(img, nc) ]
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
|
105 |
-
@
|
106 |
class C:
|
107 |
|
108 |
def Hello(self):
|
@@ -112,7 +133,7 @@ class C:
|
|
112 |
def Greeting(self, name):
|
113 |
return self.Hello() + " " + name
|
114 |
|
115 |
-
@
|
116 |
class stock_forecast:
|
117 |
|
118 |
def __init__(self):
|
|
|
1 |
import gradio as gr
|
2 |
+
import sys
|
3 |
import matplotlib
|
4 |
import matplotlib.pyplot as plt
|
5 |
import numpy as np
|
6 |
import PIL
|
|
|
|
|
7 |
|
8 |
+
sys.path.insert(0, "../resources")
|
9 |
+
from resources.module import GradioModule, register
|
10 |
|
11 |
"""
|
12 |
+
@GradioModule
|
13 |
class Pictionary:
|
14 |
|
15 |
def __init__(self) -> None:
|
|
|
46 |
return confidences
|
47 |
"""
|
48 |
|
49 |
+
@GradioModule
|
50 |
class HelloWorld_2_0:
|
51 |
|
52 |
@register(inputs=["text", "text", gr.Radio(["morning", "evening", "night"])], outputs="text")
|
|
|
66 |
|
67 |
|
68 |
|
69 |
+
@GradioModule
|
70 |
class FSD:
|
71 |
|
72 |
def get_new_val(self, old_val, nc):
|
|
|
101 |
carr = np.array(pixels / np.max(pixels, axis=(0, 1)) * 255, dtype=np.uint8)
|
102 |
return [PIL.Image.fromarray(carr), self.palette_reduce(img, nc) ]
|
103 |
|
104 |
+
@register(inputs=[gr.Image(), gr.Image(), gr.Slider(0.00, 16)], outputs=gr.Gallery())
|
105 |
+
def examples(self, img, img2, nc, ) -> 'list[PIL.Image.Image]':
|
106 |
+
pixels = np.array(img, dtype=float) / 255
|
107 |
+
new_height, new_width, _ = img.shape
|
108 |
+
for row in range(new_height):
|
109 |
+
for col in range(new_width):
|
110 |
+
old_val = pixels[row, col].copy()
|
111 |
+
new_val = self.get_new_val(old_val, nc)
|
112 |
+
pixels[row, col] = new_val
|
113 |
+
err = old_val - new_val
|
114 |
+
if col < new_width - 1:
|
115 |
+
pixels[row, col + 1] += err * 7 / 16
|
116 |
+
if row < new_height - 1:
|
117 |
+
if col > 0:
|
118 |
+
pixels[row + 1, col - 1] += err * 3 / 16
|
119 |
+
pixels[row + 1, col] += err * 5 / 16
|
120 |
+
if col < new_width - 1:
|
121 |
+
pixels[row + 1, col + 1] += err * 1 / 16
|
122 |
+
carr = np.array(pixels / np.max(pixels, axis=(0, 1)) * 255, dtype=np.uint8)
|
123 |
+
return [PIL.Image.fromarray(carr), self.palette_reduce(img, nc) ]
|
124 |
|
125 |
|
126 |
+
@GradioModule
|
127 |
class C:
|
128 |
|
129 |
def Hello(self):
|
|
|
133 |
def Greeting(self, name):
|
134 |
return self.Hello() + " " + name
|
135 |
|
136 |
+
@GradioModule
|
137 |
class stock_forecast:
|
138 |
|
139 |
def __init__(self):
|