Spaces:
Runtime error
Runtime error
| from nltk.tokenize import sent_tokenize | |
| from language_tool_python import LanguageTool | |
| from nltk.sentiment import SentimentIntensityAnalyzer | |
| import gradio as gr | |
| import nltk | |
| nltk.download('vader_lexicon') | |
| # Initialize LanguageTool object outside the function | |
| tool = LanguageTool('en-US') | |
| sia = SentimentIntensityAnalyzer() | |
| def grammar_check(text): | |
| matches = tool.check(text) | |
| corrected_sentences = tool.correct(text) | |
| return corrected_sentences | |
| def analyze_sentiment(text): | |
| sentiment_scores = sia.polarity_scores(text) | |
| # Positive sentiment: score > 0 | |
| # Neutral sentiment: score = 0 | |
| # Negative sentiment: score < 0 | |
| sentiment = "" | |
| if sentiment_scores['compound'] > 0: | |
| sentiment = "Positive" | |
| elif sentiment_scores['compound'] == 0: | |
| sentiment = "Neutral" | |
| else: | |
| sentiment = "Negative" | |
| return sentiment | |
| def sentence_generator(text): | |
| sentences = sent_tokenize(text) | |
| for sentence in sentences: | |
| yield sentence | |
| def CsharpGrammarly(text): | |
| corrected_sentences = grammar_check(text) | |
| sentiment_result = analyze_sentiment(corrected_sentences) | |
| total_words = len(text.split()) | |
| return corrected_sentences, sentiment_result, total_words | |
| iface = gr.Interface( | |
| fn=CsharpGrammarly, | |
| inputs=gr.inputs.Textbox(placeholder="Enter your text here..."), | |
| outputs=[ | |
| gr.outputs.Textbox(label="Modified Grammar"), | |
| gr.outputs.Textbox(label="Sentiment Analysis"), | |
| gr.outputs.Textbox(label="Total Words Count") | |
| ], | |
| title="CSharpGrammarly", | |
| description="Correct spelling, grammar, and analyze sentiment." | |
| ) | |
| iface.launch() |