Spaces:
Runtime error
Runtime error
File size: 1,640 Bytes
ec40672 f331055 ec40672 c89d0b4 49b04e1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
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() |