Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,30 +1,20 @@
|
|
| 1 |
-
|
| 2 |
-
import nltk
|
| 3 |
from nltk.tokenize import sent_tokenize
|
| 4 |
from language_tool_python import LanguageTool
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def grammar_check(text):
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
for sentence in sentences:
|
| 13 |
-
matches = tool.check(sentence)
|
| 14 |
-
corrected_sentence = tool.correct(sentence)
|
| 15 |
-
corrected_sentences.append(corrected_sentence)
|
| 16 |
-
corrected_text = ' '.join(corrected_sentences)
|
| 17 |
-
return corrected_text
|
| 18 |
-
|
| 19 |
-
nltk.download('vader_lexicon')
|
| 20 |
-
|
| 21 |
-
import nltk
|
| 22 |
-
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 23 |
|
| 24 |
def analyze_sentiment(text):
|
| 25 |
-
sia = SentimentIntensityAnalyzer()
|
| 26 |
sentiment_scores = sia.polarity_scores(text)
|
| 27 |
-
|
| 28 |
# Positive sentiment: score > 0
|
| 29 |
# Neutral sentiment: score = 0
|
| 30 |
# Negative sentiment: score < 0
|
|
@@ -35,21 +25,20 @@ def analyze_sentiment(text):
|
|
| 35 |
sentiment = "Neutral"
|
| 36 |
else:
|
| 37 |
sentiment = "Negative"
|
| 38 |
-
|
| 39 |
return sentiment
|
| 40 |
|
| 41 |
-
def
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
def CsharpGrammarly(text):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
import gradio as gr
|
| 53 |
iface = gr.Interface(
|
| 54 |
fn=CsharpGrammarly,
|
| 55 |
inputs=gr.inputs.Textbox(placeholder="Enter your text here..."),
|
|
@@ -62,4 +51,4 @@ iface = gr.Interface(
|
|
| 62 |
description="Correct spelling, grammar, and analyze sentiment."
|
| 63 |
)
|
| 64 |
|
| 65 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
| 1 |
from nltk.tokenize import sent_tokenize
|
| 2 |
from language_tool_python import LanguageTool
|
| 3 |
+
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 4 |
+
import gradio as gr
|
| 5 |
|
| 6 |
+
# Initialize LanguageTool object outside the function
|
| 7 |
+
tool = LanguageTool('en-US')
|
| 8 |
+
sia = SentimentIntensityAnalyzer()
|
| 9 |
|
| 10 |
def grammar_check(text):
|
| 11 |
+
matches = tool.check(text)
|
| 12 |
+
corrected_sentences = tool.correct(text)
|
| 13 |
+
return corrected_sentences
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def analyze_sentiment(text):
|
|
|
|
| 16 |
sentiment_scores = sia.polarity_scores(text)
|
| 17 |
+
|
| 18 |
# Positive sentiment: score > 0
|
| 19 |
# Neutral sentiment: score = 0
|
| 20 |
# Negative sentiment: score < 0
|
|
|
|
| 25 |
sentiment = "Neutral"
|
| 26 |
else:
|
| 27 |
sentiment = "Negative"
|
| 28 |
+
|
| 29 |
return sentiment
|
| 30 |
|
| 31 |
+
def sentence_generator(text):
|
| 32 |
+
sentences = sent_tokenize(text)
|
| 33 |
+
for sentence in sentences:
|
| 34 |
+
yield sentence
|
| 35 |
|
| 36 |
def 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_words
|
| 41 |
|
|
|
|
| 42 |
iface = gr.Interface(
|
| 43 |
fn=CsharpGrammarly,
|
| 44 |
inputs=gr.inputs.Textbox(placeholder="Enter your text here..."),
|
|
|
|
| 51 |
description="Correct spelling, grammar, and analyze sentiment."
|
| 52 |
)
|
| 53 |
|
| 54 |
+
iface.launch()
|