sumit400 commited on
Commit
6a0add5
1 Parent(s): 8f9388f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -9
app.py CHANGED
@@ -2,18 +2,15 @@ import gradio as gr
2
  import numpy as np
3
 
4
  def calculate_correlation(x_values, y_values):
5
- # Split the input strings by new lines and convert to lists of numbers
6
  try:
7
  x_values = list(map(float, x_values.split('\n')))
8
  y_values = list(map(float, y_values.split('\n')))
9
  except ValueError:
10
  return "Error: All values must be numbers."
11
-
12
- # Check if the lengths of x_values and y_values are the same
13
  if len(x_values) != len(y_values):
14
  return "Error: The number of X and Y values must be the same."
15
-
16
- # Calculate the Pearson correlation coefficient
17
  n = len(x_values)
18
  sum_x = sum(x_values)
19
  sum_y = sum(y_values)
@@ -30,12 +27,11 @@ def calculate_correlation(x_values, y_values):
30
  correlation = numerator / denominator
31
  return f"The Karl Pearson correlation coefficient is: {correlation:.10f}"
32
 
33
- # Create Gradio interface
34
  iface = gr.Interface(
35
  fn=calculate_correlation,
36
  inputs=[
37
- gr.inputs.Textbox(lines=10, placeholder="Enter X values (one per line)"),
38
- gr.inputs.Textbox(lines=10, placeholder="Enter Y values (one per line)")
39
  ],
40
  outputs="text",
41
  title="Karl Pearson Correlation Coefficient Calculator",
@@ -43,5 +39,4 @@ iface = gr.Interface(
43
  theme="compact"
44
  )
45
 
46
- # Launch the interface
47
  iface.launch()
 
2
  import numpy as np
3
 
4
  def calculate_correlation(x_values, y_values):
 
5
  try:
6
  x_values = list(map(float, x_values.split('\n')))
7
  y_values = list(map(float, y_values.split('\n')))
8
  except ValueError:
9
  return "Error: All values must be numbers."
10
+
 
11
  if len(x_values) != len(y_values):
12
  return "Error: The number of X and Y values must be the same."
13
+
 
14
  n = len(x_values)
15
  sum_x = sum(x_values)
16
  sum_y = sum(y_values)
 
27
  correlation = numerator / denominator
28
  return f"The Karl Pearson correlation coefficient is: {correlation:.10f}"
29
 
 
30
  iface = gr.Interface(
31
  fn=calculate_correlation,
32
  inputs=[
33
+ gr.components.Textbox(lines=10, placeholder="Enter X values (one per line)"),
34
+ gr.components.Textbox(lines=10, placeholder="Enter Y values (one per line)")
35
  ],
36
  outputs="text",
37
  title="Karl Pearson Correlation Coefficient Calculator",
 
39
  theme="compact"
40
  )
41
 
 
42
  iface.launch()