Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
11 |
-
from transformers import T5ForConditionalGeneration, T5Tokenizer
|
12 |
|
13 |
-
|
14 |
-
explain_tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-large")
|
15 |
|
16 |
-
|
17 |
-
|
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 |
-
|
38 |
-
|
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)
|
|
|
|
|
|
|
|