Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,31 +1,33 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
-
import difflib
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
7 |
|
8 |
-
|
9 |
-
|
10 |
-
revised = pipe(prompt, max_new_tokens=1024)[0]['generated_text']
|
11 |
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
explanation = "No significant changes were made. Minor improvements only."
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
-
# Set up Gradio interface
|
25 |
-
gr.Interface(
|
26 |
-
fn=respond,
|
27 |
-
inputs="text",
|
28 |
-
outputs="text",
|
29 |
-
title="Free AI Essay Bot",
|
30 |
-
description="Paste an essay below. The AI will revise it and explain the changes."
|
31 |
-
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
|
|
3 |
|
4 |
+
# Load the faster model
|
5 |
+
model_name = "pszemraj/flan-t5-base-grammar-synthesis" # ✅ Use flan-t5-base (faster)
|
6 |
+
pipe = pipeline("text2text-generation", model=model_name, max_new_tokens=200)
|
7 |
|
8 |
+
# Word limit (adjust as needed)
|
9 |
+
MAX_WORDS = 500
|
|
|
10 |
|
11 |
+
def check_essay(essay):
|
12 |
+
# Word limit enforcement
|
13 |
+
words = essay.strip().split()
|
14 |
+
if len(words) > MAX_WORDS:
|
15 |
+
return f"❗ Your essay is too long. Please limit it to {MAX_WORDS} words or less."
|
16 |
|
17 |
+
# Run model
|
18 |
+
result = pipe(essay, max_new_tokens=200, temperature=0.5)
|
19 |
+
corrected_text = result[0]['generated_text']
|
20 |
+
return corrected_text
|
|
|
21 |
|
22 |
+
# Gradio interface
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=check_essay,
|
25 |
+
inputs=gr.Textbox(lines=20, placeholder="Paste your essay here..."),
|
26 |
+
outputs=gr.Textbox(label="Revised Essay"),
|
27 |
+
title="Essay Checker (Fast & Free)",
|
28 |
+
description=f"Check and improve your essay instantly. Max {MAX_WORDS} words for speed."
|
29 |
+
)
|
30 |
+
|
31 |
+
if __name__ == "__main__":
|
32 |
+
iface.launch()
|
33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|