Spaces:
Sleeping
Sleeping
File size: 1,360 Bytes
598afbb 4c2c95d 598afbb 4c2c95d 7394131 6824046 598afbb 4c2c95d 598afbb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
import gradio as gr
def calculate_stats(numbers):
"""
Calculate the average and standard deviation of a list of numbers.
"""
if not numbers:
return "Error: No numbers provided"
try:
if isinstance(numbers, str):
numbers = numbers.split(',')
numbers = [float(num.strip()) for num in numbers]
average = sum(numbers) / len(numbers)
std_dev = (sum((x - average) ** 2 for x in numbers) / len(numbers)) ** 0.5
return f"Average: {average}\nStandard Deviation: {std_dev}"
except ValueError:
return "Error: All inputs must be numeric"
except Exception as e:
return f"Error: {str(e)}"
def main():
with gr.Blocks() as demo:
gr.Markdown("# Average and Standard Deviation Calculator")
with gr.Row():
numbers_input = gr.Textbox(label="Enter numbers (separate by commas)")
calculate_button = gr.Button("Calculate")
with gr.Row():
result_output = gr.Markdown(label="Results")
def calculate_and_display(numbers):
stats = calculate_stats(numbers)
return stats
calculate_button.click(
fn=calculate_and_display,
inputs=[numbers_input],
outputs=[result_output]
)
demo.launch()
if __name__ == "__main__":
main()
|