Vivek12345323 commited on
Commit
71e359d
ยท
verified ยท
1 Parent(s): 54d16dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -6,26 +6,26 @@ import difflib
6
  pipe = pipeline("text2text-generation", model="pszemraj/flan-t5-large-grammar-synthesis")
7
 
8
  def respond(prompt):
9
- # Generate revised essay
10
- revised = pipe(prompt, max_new_tokens=512)[0]['generated_text']
11
 
12
- # Generate a word-level diff
13
- diff = difflib.ndiff(prompt.split(), revised.split())
14
- changes = [line for line in diff if line.startswith("- ") or line.startswith("+ ")]
15
 
16
- # Format explanation
17
- if changes:
18
- explanation = "\n".join(changes)
19
- else:
20
- explanation = "No significant changes were made. Minor improvements only."
21
 
22
- return f"๐Ÿ“ Revised Essay:\n\n{revised}\n\n๐Ÿ› ๏ธ Explanation of Changes:\n\n{explanation}"
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()
 
6
  pipe = pipeline("text2text-generation", model="pszemraj/flan-t5-large-grammar-synthesis")
7
 
8
  def respond(prompt):
9
+ # Generate revised essay
10
+ revised = pipe(prompt, max_new_tokens=512)[0]['generated_text']
11
 
12
+ # Generate a word-level diff
13
+ diff = difflib.ndiff(prompt.split(), revised.split())
14
+ changes = [line for line in diff if line.startswith("- ") or line.startswith("+ ")]
15
 
16
+ # Format explanation
17
+ if changes:
18
+ explanation = "\n".join(changes)
19
+ else:
20
+ explanation = "No significant changes were made. Minor improvements only."
21
 
22
+ return f"๐Ÿ“ Revised Essay:\n\n{revised}\n\n๐Ÿ› ๏ธ Explanation of Changes:\n\n{explanation}"
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()