Spaces:
Paused
Paused
Update app.py
Browse files1 unmodified line2345678910111213141516171819201 unmodified line2223242526272829303132333435363738394041424344454647484950515253545556575859606162631 unmodified lineimport gradio as grimport pandas as pdimport matplotlib.pyplot as plt# Use a pipeline as a high-level helperfrom transformers import pipelineanalyzer = pipeline("text-classification",model="dicta-il/dictalm2.0")# analyzer = pipeline("text-classification",# model=model_path)# print(analyzer(["This production is good", "This product was quite expensive"]))def sentiment_analyzer(review):sentiment = analyzer(review)1 unmodified linedef sentiment_bar_chart(df):sentiment_counts = df['Sentiment'].value_counts()# Create a bar chartfig, ax = plt.subplots()sentiment_counts.plot(kind='pie', ax=ax, autopct='%1.1f%%', color=['green', 'red'])ax.set_title('Review Sentiment Counts')ax.set_xlabel('Sentiment')ax.set_ylabel('Count')# ax.set_xticklabels(['Positive', 'Negative'], rotation=0)# Return the figure objectreturn figdef read_reviews_and_analyze_sentiment(file_object):# Load the Excel file into a DataFramedf = pd.read_excel(file_object)# Check if 'Review' column is in the DataFrameif 'Reviews' not in df.columns:raise ValueError("Excel file must contain a 'Review' column.")# Apply the get_sentiment function to each review in the DataFramedf['Sentiment'] = df['Reviews'].apply(sentiment_analyzer)chart_object = sentiment_bar_chart(df)return df, chart_object# result = read_reviews_and_analyze_sentiment("../Files/Prod-review.xlsx")# print(result)# Example usage:# df = read_reviews_and_analyze_sentiment('path_to_your_excel_file.xlsx')# print(df)demo = gr.Interface(fn=read_reviews_and_analyze_sentiment,inputs=[gr.File(file_types=["xlsx"], label="Upload your review comment file")],outputs=[gr.Dataframe(label="Sentiments"), gr.Plot(label="Sentiment Analysis")],title="Sentiment Analyzer",description="THIS APPLICATION WILL BE USED TO ANALYZE THE SENTIMENT BASED ON FILE UPLAODED.")demo.launch()1 unmodified line2345678910111 unmodified line1314151617181920212223242526272829303132333435363738394041421 unmodified lineimport gradio as grimport pandas as pdimport matplotlib.pyplot as pltfrom transformers import pipeline# Use a pipeline with a model suitable for sentiment analysisanalyzer = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")def sentiment_analyzer(review):sentiment = analyzer(review)1 unmodified linedef sentiment_bar_chart(df):sentiment_counts = df['Sentiment'].value_counts()# Create a bar chartfig, ax = plt.subplots()sentiment_counts.plot(kind='pie', ax=ax, autopct='%1.1f%%', colors=['green', 'red'])ax.set_title('Review Sentiment Counts')ax.set_xlabel('Sentiment')ax.set_ylabel('Count')return figdef read_reviews_and_analyze_sentiment(file_object):# Load the Excel file into a DataFramedf = pd.read_excel(file_object)# Check if 'Reviews' column is in the DataFrameif 'Reviews' not in df.columns:raise ValueError("Excel file must contain a 'Reviews' column.")# Apply the sentiment analysis function to each review in the DataFramedf['Sentiment'] = df['Reviews'].apply(sentiment_analyzer)chart_object = sentiment_bar_chart(df)return df, chart_objectgr.close_all()demo = gr.Interface(fn=read_reviews_and_analyze_sentiment,inputs=[gr.File(file_types=["xlsx"], label="Upload your review comment file")],outputs=[gr.Dataframe(label="Sentiments"), gr.Plot(label="Sentiment Analysis")],title="Sentiment Analyzer",description="This application will be used to analyze the sentiment based on the uploaded file.")demo.launch()
app.py+9-30