Spaces:
Sleeping
Sleeping
add app
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def calculate_stats(numbers):
|
| 4 |
+
"""
|
| 5 |
+
Calculate the average and standard deviation of a list of numbers.
|
| 6 |
+
"""
|
| 7 |
+
if not numbers:
|
| 8 |
+
return "Error: No numbers provided"
|
| 9 |
+
|
| 10 |
+
try:
|
| 11 |
+
average = sum(numbers) / len(numbers)
|
| 12 |
+
std_dev = (sum((x - average) ** 2 for x in numbers) / len(numbers)) ** 0.5
|
| 13 |
+
return f"Average: {average:.2f}\nStandard Deviation: {std_dev:.2f}"
|
| 14 |
+
except Exception as e:
|
| 15 |
+
return f"Error: {str(e)}"
|
| 16 |
+
|
| 17 |
+
def main():
|
| 18 |
+
with gr.Blocks() as demo:
|
| 19 |
+
gr.Markdown("# Average and Standard Deviation Calculator")
|
| 20 |
+
|
| 21 |
+
with gr.Row():
|
| 22 |
+
numbers_input = gr.List(label="Enter numbers (separate by commas)", input_type="number")
|
| 23 |
+
calculate_button = gr.Button("Calculate")
|
| 24 |
+
|
| 25 |
+
with gr.Row():
|
| 26 |
+
result_output = gr.Markdown(label="Results")
|
| 27 |
+
|
| 28 |
+
def calculate_and_display(numbers):
|
| 29 |
+
stats = calculate_stats(numbers)
|
| 30 |
+
return stats
|
| 31 |
+
|
| 32 |
+
calculate_button.click(
|
| 33 |
+
fn=calculate_and_display,
|
| 34 |
+
inputs=[numbers_input],
|
| 35 |
+
outputs=[result_output]
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
demo.launch()
|
| 39 |
+
|
| 40 |
+
if __name__ == "__main__":
|
| 41 |
+
main()
|