arsath-sm commited on
Commit
288b4d9
·
verified ·
1 Parent(s): 16450b1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
3
+ import torch
4
+
5
+ # Load the model and tokenizer
6
+ model_name = 'abinayam/gpt-2-tamil'
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForCausalLM.from_pretrained(model_name)
9
+
10
+ def correct_text(input_text):
11
+ # Tokenize the input text
12
+ input_ids = tokenizer.encode(input_text, return_tensors='pt')
13
+
14
+ # Generate corrected text
15
+ with torch.no_grad():
16
+ output = model.generate(input_ids, max_length=100, num_return_sequences=1, temperature=0.7)
17
+
18
+ # Decode the generated text
19
+ corrected_text = tokenizer.decode(output[0], skip_special_tokens=True)
20
+
21
+ return corrected_text
22
+
23
+ # Create the Gradio interface
24
+ iface = gr.Interface(
25
+ fn=correct_text,
26
+ inputs=gr.Textbox(lines=5, placeholder="Enter Tamil text here..."),
27
+ outputs=gr.Textbox(label="Corrected Text"),
28
+ title="Tamil Spell Corrector and Grammar Checker",
29
+ description="This app uses the 'abinayam/gpt-2-tamil' model to correct spelling and grammar in Tamil text.",
30
+ )
31
+
32
+ # Launch the app
33
+ iface.launch()