import gradio as gr import pandas as pd from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.cluster import KMeans labels = {} def get_sentiment(input_txt, k): data = input_txt.splitlines() df = pd.DataFrame(data, columns=["content"]) vec = TfidfVectorizer() features = vec.fit_transform(df["content"]) kmeans = KMeans(k, n_init=10, random_state=42) kmeans.fit(features) df['kmeans'] = kmeans.labels_ labels = df['kmeans'].value_counts(normalize=True).to_dict() return labels iface = gr.Interface(fn= get_sentiment, inputs = [gr.inputs.Textbox(lines=8, placeholder="News Here..."), gr.inputs.Slider(1, 101)], outputs = ["label"], title = "Short Document Clustering") if __name__ == "__main__": app, local_url, share_url = iface.launch()