Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
|
4 |
+
|
5 |
+
def gennerateImage(input_array,eps):
|
6 |
+
eps = eps / 100
|
7 |
+
mask = np.random.random(input_array.shape)
|
8 |
+
mask = mask * 2 - 1 # 将mask的值转换为-1到1之间
|
9 |
+
noise_img = (input_array * (1 + mask * eps)).astype(np.uint8) % 255
|
10 |
+
return noise_img
|
11 |
+
|
12 |
+
demo = gr.Interface(
|
13 |
+
gennerateImage,
|
14 |
+
inputs=[
|
15 |
+
gr.Image(),
|
16 |
+
gr.Slider(1, 10, 3)
|
17 |
+
],
|
18 |
+
outputs="image"
|
19 |
+
)
|
20 |
+
|
21 |
+
demo.launch()
|