Spaces:
Build error
Build error
Create App.py
Browse files
App.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import nltk
|
| 2 |
+
from nltk.tokenize import sent_tokenize
|
| 3 |
+
from language_tool_python import LanguageTool
|
| 4 |
+
|
| 5 |
+
nltk.download('punkt')
|
| 6 |
+
|
| 7 |
+
def grammar_check(text):
|
| 8 |
+
tool = LanguageTool('en-US')
|
| 9 |
+
sentences = sent_tokenize(text)
|
| 10 |
+
corrected_sentences = []
|
| 11 |
+
for sentence in sentences:
|
| 12 |
+
matches = tool.check(sentence)
|
| 13 |
+
corrected_sentence = tool.correct(sentence)
|
| 14 |
+
corrected_sentences.append(corrected_sentence)
|
| 15 |
+
corrected_text = ' '.join(corrected_sentences)
|
| 16 |
+
return corrected_text
|
| 17 |
+
|
| 18 |
+
nltk.download('vader_lexicon')
|
| 19 |
+
|
| 20 |
+
import nltk
|
| 21 |
+
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 22 |
+
|
| 23 |
+
def analyze_sentiment(text):
|
| 24 |
+
sia = SentimentIntensityAnalyzer()
|
| 25 |
+
sentiment_scores = sia.polarity_scores(text)
|
| 26 |
+
|
| 27 |
+
# Positive sentiment: score > 0
|
| 28 |
+
# Neutral sentiment: score = 0
|
| 29 |
+
# Negative sentiment: score < 0
|
| 30 |
+
sentiment = ""
|
| 31 |
+
if sentiment_scores['compound'] > 0:
|
| 32 |
+
sentiment = "Positive"
|
| 33 |
+
elif sentiment_scores['compound'] == 0:
|
| 34 |
+
sentiment = "Neutral"
|
| 35 |
+
else:
|
| 36 |
+
sentiment = "Negative"
|
| 37 |
+
|
| 38 |
+
return sentiment
|
| 39 |
+
|
| 40 |
+
def count_words(text):
|
| 41 |
+
words = text.split()
|
| 42 |
+
total_words = len(words)
|
| 43 |
+
return total_words
|
| 44 |
+
|
| 45 |
+
def CsharpGrammarly(text):
|
| 46 |
+
result1= grammar_check(text)
|
| 47 |
+
sentiment_result= analyze_sentiment(result1)
|
| 48 |
+
total_words= count_words(result1)
|
| 49 |
+
return result1,sentiment_result,total_words
|
| 50 |
+
|
| 51 |
+
import gradio as gr
|
| 52 |
+
iface = gr.Interface(
|
| 53 |
+
fn=CsharpGrammarly,
|
| 54 |
+
inputs=gr.inputs.Textbox(placeholder="Enter your text here..."),
|
| 55 |
+
outputs=[
|
| 56 |
+
gr.outputs.Textbox(label="Modified Grammar"),
|
| 57 |
+
gr.outputs.Textbox(label="Sentiment Analysis"),
|
| 58 |
+
gr.outputs.Textbox(label="Total Words Count")
|
| 59 |
+
],
|
| 60 |
+
title="CSharpGrammarly",
|
| 61 |
+
description="Correct spelling, grammar, and analyze sentiment."
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
iface.launch()
|