Priyanhsu/CsharpGrammarly
0
1from nltk.tokenize import sent_tokenize2from language_tool_python import LanguageTool3from nltk.sentiment import SentimentIntensityAnalyzer4import gradio as gr5 6# Initialize LanguageTool object outside the function7tool = LanguageTool('en-US')8sia = SentimentIntensityAnalyzer()9 10def grammar_check(text):11 matches = tool.check(text)12 corrected_sentences = tool.correct(text)13 return corrected_sentences14 15def analyze_sentiment(text):16 sentiment_scores = sia.polarity_scores(text)17 18 # Positive sentiment: score > 019 # Neutral sentiment: score = 020 # Negative sentiment: score < 021 sentiment = ""22 if sentiment_scores['compound'] > 0:23 sentiment = "Positive"24 elif sentiment_scores['compound'] == 0:25 sentiment = "Neutral"26 else:27 sentiment = "Negative"28 29 return sentiment30 31def sentence_generator(text):32 sentences = sent_tokenize(text)33 for sentence in sentences:34 yield sentence35 36def CsharpGrammarly(text):37 corrected_sentences = grammar_check(text)38 sentiment_result = analyze_sentiment(corrected_sentences)39 total_words = len(text.split())40 return corrected_sentences, sentiment_result, total_words41 42iface = gr.Interface(43 fn=CsharpGrammarly,44 inputs=gr.inputs.Textbox(placeholder="Enter your text here..."),45 outputs=[46 gr.outputs.Textbox(label="Modified Grammar"),47 gr.outputs.Textbox(label="Sentiment Analysis"),48 gr.outputs.Textbox(label="Total Words Count")49 ],50 title="CSharpGrammarly",51 description="Correct spelling, grammar, and analyze sentiment."52)53 54iface.launch()55 