Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import numpy | |
| import matplotlib.pyplot as plt | |
| #!pip install tslearn | |
| from tslearn.clustering import KernelKMeans | |
| from tslearn.preprocessing import TimeSeriesScalerMeanVariance | |
| from tslearn.datasets import UCR_UEA_datasets | |
| numpy.random.seed(42) | |
| X_train, y_train, X_test, y_test = UCR_UEA_datasets().load_dataset("PickupGestureWiimoteZ") | |
| X_train = TimeSeriesScalerMeanVariance().fit_transform(X_train) | |
| sz = X_train.shape[1] | |
| gak_km = KernelKMeans(n_clusters=10, | |
| kernel="gak", | |
| kernel_params={"sigma": "auto"}, | |
| n_init=10, | |
| verbose=True, | |
| random_state=42) | |
| y_pred = gak_km.fit_predict(X_train) | |
| #def process_file(file): | |
| #plt.figure() | |
| #for yi in range(10): | |
| # plt.subplot(10, 1, 1 + yi) | |
| # for xx in X_train[y_pred == yi]: | |
| # plt.plot(xx.ravel(), "k-", alpha=.2) | |
| # plt.xlim(0, sz) | |
| # plt.ylim(-4, 4) | |
| # plt.title("Cluster %d" % (yi + 1)) | |
| #plt.tight_layout() | |
| #plt.show() | |
| #df = pd.read_csv(file.name, index_col=False) | |
| #network = dtwsom.DtwSom(2, 2, type_conn.honeycomb) | |
| #network.train(df.values.tolist(), 100) | |
| #return plt | |
| #iface = gr.Interface(fn=sketch_recognition, inputs="sketchpad", outputs="label").launch() | |
| #iface = gr.Interface( | |
| # process_file, | |
| # inputs="file", | |
| # outputs=["plot"], | |
| # examples=["golf.csv"] | |
| #) | |
| #iface.launch(debug=False) | |
| def sentence_builder(quantity, animal, place, activity_list, morning): | |
| return f"""The {quantity} {animal}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}""" | |
| iface = gr.Interface( | |
| sentence_builder, | |
| [ | |
| gr.inputs.Slider(2, 20), | |
| gr.inputs.Dropdown(["cat", "dog", "bird"]), | |
| gr.inputs.Radio(["park", "zoo", "road"]), | |
| gr.inputs.CheckboxGroup(["ran", "swam", "ate", "slept"]), | |
| gr.inputs.Checkbox(label="Is it the morning?"), | |
| ], | |
| "text", | |
| examples=[ | |
| [2, "cat", "park", ["ran", "swam"], True], | |
| [4, "dog", "zoo", ["ate", "swam"], False], | |
| [10, "bird", "road", ["ran"], False], | |
| [8, "cat", "zoo", ["ate"], True], | |
| ], | |
| ) | |
| iface.launch() |