Spaces:
Sleeping
Sleeping
import gradio as gr | |
import numpy as np | |
import matplotlib.pyplot as plt | |
def process_inputs(function_type, amplitude, frequency, text): | |
"""Procesa múltiples entradas""" | |
# Generar visualización matemática | |
x = np.linspace(0, 10, 500) | |
plt.figure(figsize=(10, 6)) | |
plt.title(f"Función: {function_type}") | |
if function_type == "Senoidal": | |
y = amplitude * np.sin(frequency * x) | |
elif function_type == "Cosenoidal": | |
y = amplitude * np.cos(frequency * x) | |
elif function_type == "Exponencial": | |
y = amplitude * np.exp(-frequency * x) | |
plt.plot(x, y) | |
plt.grid(True) | |
plt.xlabel("Eje X") | |
plt.ylabel("Amplitud") | |
# Análisis de texto | |
text_analysis = { | |
"Longitud": len(text), | |
"Palabras": len(text.split()), | |
"Mayúsculas": sum(1 for c in text if c.isupper()), | |
"Minúsculas": sum(1 for c in text if c.islower()) | |
} | |
return plt, text_analysis | |
# Crear interfaz de Gradio con la función especificada | |
demo = gr.Interface( | |
fn=process_inputs, # Añadido el argumento fn | |
title="Demo Interactiva Multifuncional", | |
description="Visualización matemática y análisis de texto", | |
inputs=[ | |
gr.Dropdown(["Senoidal", "Cosenoidal", "Exponencial"], label="Tipo de Función"), | |
gr.Slider(minimum=0.1, maximum=5, value=1, label="Amplitud"), | |
gr.Slider(minimum=0.1, maximum=5, value=1, label="Frecuencia"), | |
gr.Textbox(label="Texto para Análisis") | |
], | |
outputs=[ | |
gr.Plot(label="Visualización Matemática"), | |
gr.JSON(label="Análisis de Texto") | |
] | |
) | |
demo.launch() |