rubend18 commited on
Commit
960447f
1 Parent(s): 883e6e2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -0
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+
4
+ def entropy_calculator(values):
5
+ n = len(values)
6
+
7
+ counts = np.bincount(values)
8
+ probabilities = counts[np.nonzero(counts)] / n
9
+
10
+ result = 0
11
+ for i in range(len(probabilities)):
12
+ result = result - probabilities[i] * np.log(probabilities[i])/np.log(2)
13
+
14
+ return result
15
+
16
+ def function(values):
17
+ substrings = values.split(',')
18
+ return entropy_calculator(substrings)
19
+
20
+ value1 = gr.Textbox(lines=3, label="Values", placeholder="Please enter the values separated by commas...")
21
+ value2 = gr.Textbox(lines=3, label="Entropy", placeholder="Entropy...")
22
+
23
+ examples = [
24
+ ["1,2,3,4,5,6,7,8,9"],
25
+ ["1,1,1,1,1,1,1,1,2"],
26
+ ["1,2,1,2,1,2,1,2,1"],
27
+ ["8,8,8,8,8,8,8,8,8"],
28
+ ["1,2,3,1,2,3,1,2,3"]
29
+ ]
30
+
31
+ demo = gr.Interface(
32
+ fn=function,
33
+ inputs=value1,
34
+ outputs=value2,
35
+ title="Entropy calculator",
36
+ examples=examples,
37
+ description="Calculate the entropy of a set of values."
38
+ )
39
+
40
+ demo.launch(debug=True)