import pandas as pd import matplotlib.pyplot as plt from wordcloud import WordCloud import seaborn as sns import gradio as gr def generate_wordcloud(text, title): wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text) plt.figure(figsize=(10, 5)) plt.imshow(wordcloud, interpolation='bilinear') plt.axis('off') plt.title(title) plt.show() def generate_bar_plot(data, x, y, title): plt.figure(figsize=(10, 5)) sns.barplot(x=x, y=y, data=data) plt.title(title) plt.show() def generate_line_plot(data, x, y, title): plt.figure(figsize=(10, 5)) sns.lineplot(x=x, y=y, data=data) plt.title(title) plt.show() def sentiment_analysis(csv_file): # Load CSV file df = pd.read_csv(csv_file) # Assuming you have a 'Sentiment' column in your CSV indicating positive or negative sentiment # Positive Sentiment positive_df = df[df['Sentiment'] == 'positive'] positive_text = ' '.join(positive_df['Content']) generate_wordcloud(positive_text, 'Positive Sentiment Word Cloud') generate_bar_plot(positive_df, 'Label', 'Count', 'Positive Sentiment Distribution') generate_line_plot(positive_df, 'Created At', 'SentimentScore', 'Positive Sentiment over Time') # Negative Sentiment negative_df = df[df['Sentiment'] == 'negative'] negative_text = ' '.join(negative_df['Content']) generate_wordcloud(negative_text, 'Negative Sentiment Word Cloud') generate_bar_plot(negative_df, 'Label', 'Count', 'Negative Sentiment Distribution') generate_line_plot(negative_df, 'Created At', 'SentimentScore', 'Negative Sentiment over Time') # Gradio Interface csv_file_input = gr.inputs.File(label="Select CSV file") interface = gr.Interface(fn=sentiment_analysis, inputs=csv_file_input, outputs=None, title="Sentiment Analysis", description="Generates word clouds, bar plots, and line plots based on sentiment of text data from CSV files") interface.launch()