ahmadsanafarooq commited on
Commit
4726fe1
·
verified ·
1 Parent(s): dd86c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -22
app.py CHANGED
@@ -1,33 +1,23 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load pre-trained models
5
- sentiment_pipeline = pipeline("sentiment-analysis") # Sentiment Analysis
6
- summarizer_pipeline = pipeline("summarization") # Summarization
7
- translation_pipeline = pipeline("translation_en_to_ur") # English to Urdu Translation
8
 
9
- def nlp_tasks(text):
 
10
  if not text.strip():
11
- return "Please enter valid text", "", ""
12
-
13
- # NLP Tasks
14
- sentiment = sentiment_pipeline(text)[0]['label']
15
- summary = summarizer_pipeline(text, max_length=60, min_length=25, do_sample=False)[0]['summary_text']
16
- translation = translation_pipeline(text)[0]['translation_text']
17
-
18
- return sentiment, summary, translation
19
 
20
  # Gradio Interface
21
  interface = gr.Interface(
22
- fn=nlp_tasks,
23
- inputs=gr.Textbox(lines=5, placeholder="Enter your text here...", label="Input Text"),
24
- outputs=[
25
- gr.Textbox(label="Sentiment"),
26
- gr.Textbox(label="Summary"),
27
- gr.Textbox(label="Urdu Translation")
28
- ],
29
- title="Beginner NLP App",
30
- description="This beginner-friendly app uses Hugging Face Transformers to perform Sentiment Analysis, Summarization, and English to Urdu Translation."
31
  )
32
 
33
  if __name__ == "__main__":
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Load grammar correction pipeline using T5
5
+ grammar_correction = pipeline("text2text-generation", model="vennify/t5-base-grammar-correction")
 
 
6
 
7
+ # Function to correct grammar
8
+ def correct_grammar(text):
9
  if not text.strip():
10
+ return "Please enter some text."
11
+ corrected = grammar_correction(f"grammar: {text}", max_length=128, clean_up_tokenization_spaces=True)[0]['generated_text']
12
+ return corrected
 
 
 
 
 
13
 
14
  # Gradio Interface
15
  interface = gr.Interface(
16
+ fn=correct_grammar,
17
+ inputs=gr.Textbox(lines=5, placeholder="Enter your sentence with grammar mistakes...", label="Your Text"),
18
+ outputs=gr.Textbox(label="Corrected Text"),
19
+ title="📝 AI Grammar Corrector",
20
+ description="This app uses a fine-tuned T5 model to correct grammar and style. Powered by 🤗 Hugging Face Transformers."
 
 
 
 
21
  )
22
 
23
  if __name__ == "__main__":