ZeeAI1 commited on
Commit
7642bfd
·
verified ·
1 Parent(s): 8565ea2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -30
app.py CHANGED
@@ -7,39 +7,16 @@ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
  pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
9
 
10
- # Load explanation model
11
- from transformers import T5ForConditionalGeneration, T5Tokenizer
12
 
13
- explain_model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-large")
14
- explain_tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
15
 
16
- def correct_text(text):
17
- input_text = "gec: " + text
18
- result = pipe(input_text, max_length=512, clean_up_tokenization_spaces=True)
19
- return result[0]['generated_text']
20
-
21
- def explain_corrections(original, corrected):
22
- prompt = f"""Original: {original}
23
- Corrected: {corrected}
24
- Explain the changes made, identify grammar or spelling issues, and give writing improvement tips."""
25
- inputs = explain_tokenizer(prompt, return_tensors="pt", truncation=True)
26
- outputs = explain_model.generate(**inputs, max_length=512)
27
- return explain_tokenizer.decode(outputs[0], skip_special_tokens=True)
28
-
29
- # Streamlit UI
30
- st.title("✍️ English Writing Assistant")
31
- user_input = st.text_area("Enter your sentence, paragraph, or essay:")
32
-
33
- if st.button("Check & Improve"):
34
- if user_input.strip() == "":
35
  st.warning("Please enter some text.")
36
  else:
37
- corrected = correct_text(user_input)
38
- explanation = explain_corrections(user_input, corrected)
39
-
40
  st.subheader("✅ Corrected Text:")
41
  st.write(corrected)
42
-
43
- st.subheader("📘 Explanation & Suggestions:")
44
- st.write(explanation)
45
-
 
7
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
  pipe = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
9
 
10
+ st.title("✍️ English Grammar & Writing Assistant")
 
11
 
12
+ text = st.text_area("Enter your sentence or paragraph:")
 
13
 
14
+ if st.button("Correct Text"):
15
+ if not text.strip():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  st.warning("Please enter some text.")
17
  else:
18
+ input_text = "gec: " + text
19
+ result = pipe(input_text, max_length=512)
20
+ corrected = result[0]['generated_text']
21
  st.subheader("✅ Corrected Text:")
22
  st.write(corrected)