ABAO77 commited on
Commit
e8f24c0
·
verified ·
1 Parent(s): a90d1e4

Upload grammar_checker.py

Browse files
Files changed (1) hide show
  1. grammar_checker.py +1 -15
grammar_checker.py CHANGED
@@ -9,7 +9,6 @@ from langchain.prompts import ChatPromptTemplate
9
  from langchain_text_splitters import RecursiveCharacterTextSplitter
10
  from models import Grammar, Error
11
  import docx
12
- from rich.console import Console
13
  from rich.table import Table
14
  from rich.box import ROUNDED
15
  import re
@@ -19,7 +18,6 @@ import pandas as pd
19
  logger.add("grammar_checker.log", rotation="500 MB", level="DEBUG")
20
 
21
  # Create console for rich output
22
- console = Console()
23
 
24
  # Get Azure OpenAI credentials from environment variables
25
  AZURE_OPENAI_API_KEY = os.environ.get("AZURE_OPENAI_API_KEY")
@@ -515,7 +513,6 @@ def display_results(response: Grammar, path: str = "", repo_link: str = "") -> i
515
  path = "Text input"
516
 
517
  # Print the file path
518
- console.print(f"\n[bold cyan]File: {path}[/bold cyan]")
519
 
520
  total_errors = 0
521
 
@@ -534,22 +531,11 @@ def display_results(response: Grammar, path: str = "", repo_link: str = "") -> i
534
  total_errors += 1
535
 
536
  if errors:
537
- console.print(table)
538
  else:
539
  no_errors_msg = f"No {category} errors found."
540
- console.print(f"[blue]{no_errors_msg}[/blue]")
541
 
542
- console.print(
543
- f"[bold {'green' if total_errors == 0 else 'red'}]Total errors found: {total_errors}[/bold]"
544
- )
545
 
546
- # Display corrected text if available
547
- if response.corrected_text:
548
- console.print("\n[bold cyan]Fully Corrected Text:[/bold cyan]")
549
- console.print(response.corrected_text)
550
 
551
- # Write output to a file
552
- with open("grammar_results.txt", "w") as f:
553
- f.write(console.export_text())
554
 
555
  return total_errors
 
9
  from langchain_text_splitters import RecursiveCharacterTextSplitter
10
  from models import Grammar, Error
11
  import docx
 
12
  from rich.table import Table
13
  from rich.box import ROUNDED
14
  import re
 
18
  logger.add("grammar_checker.log", rotation="500 MB", level="DEBUG")
19
 
20
  # Create console for rich output
 
21
 
22
  # Get Azure OpenAI credentials from environment variables
23
  AZURE_OPENAI_API_KEY = os.environ.get("AZURE_OPENAI_API_KEY")
 
513
  path = "Text input"
514
 
515
  # Print the file path
 
516
 
517
  total_errors = 0
518
 
 
531
  total_errors += 1
532
 
533
  if errors:
534
+ print(table)
535
  else:
536
  no_errors_msg = f"No {category} errors found."
 
537
 
 
 
 
538
 
 
 
 
 
539
 
 
 
 
540
 
541
  return total_errors