Rybib commited on
Commit
fa2dad9
·
verified ·
1 Parent(s): 014df01

Upload EDEN model and code

Browse files
README.md CHANGED
@@ -52,16 +52,38 @@ First install the two dependencies (one time):
52
  pip3 install torch transformers
53
  ```
54
 
55
- ### Option 1: one terminal command
56
 
57
- Paste this whole line into your terminal. It downloads the model the first time
58
- and prints the cleaned-up sentence:
 
59
 
60
  ```bash
61
- python3 -c "from transformers import AutoModel, AutoTokenizer; t=AutoTokenizer.from_pretrained('Rybib/EDEN'); m=AutoModel.from_pretrained('Rybib/EDEN', trust_remote_code=True).eval(); print(m.enhance(t, 'i relly wnt this to sound beter'))"
62
  ```
63
 
64
- ### Option 2: a Python script
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  The lines below are Python, not terminal commands. Save them as a file such as
67
  `run.py`, then run `python3 run.py`. Do not paste them straight into the
@@ -72,7 +94,7 @@ from transformers import AutoModel, AutoTokenizer
72
 
73
  model_id = "Rybib/EDEN"
74
 
75
- tokenizer = AutoTokenizer.from_pretrained(model_id)
76
  model = AutoModel.from_pretrained(model_id, trust_remote_code=True).eval()
77
 
78
  rough = "i relly wnt this sentance to sound more profesional"
@@ -80,19 +102,6 @@ print(model.enhance(tokenizer, rough))
80
  # I really want this sentence to sound more professional.
81
  ```
82
 
83
- ### Option 3: interactive helper script
84
-
85
- This repository includes `examples/try_eden.py`, which loads the model and lets
86
- you type text and get it cleaned up:
87
-
88
- ```bash
89
- python3 examples/try_eden.py # interactive
90
- python3 examples/try_eden.py "fix this sentance" # one-shot
91
- ```
92
-
93
- macOS users can also double-click `Try EDEN.command` to open an interactive
94
- session in a terminal window.
95
-
96
  The `enhance` method handles long inputs by splitting them into sentence-aware
97
  chunks, rewriting each chunk, and joining the results.
98
 
 
52
  pip3 install torch transformers
53
  ```
54
 
55
+ ### Option 1: chat with EDEN in the terminal (recommended)
56
 
57
+ This opens a simple interactive interface, similar to Ollama. Type or paste
58
+ rough text, press Enter, and get the cleaned-up version. Type `/bye` or press
59
+ Ctrl+D to quit.
60
 
61
  ```bash
62
+ python3 examples/try_eden.py
63
  ```
64
 
65
+ macOS users can also double-click `Try EDEN.command` to open the same interface
66
+ in a terminal window.
67
+
68
+ Example session:
69
+
70
+ ```text
71
+ >>> their are alot of reasons why this dont work proper
72
+ There are a lot of reasons why this do not work proper.
73
+
74
+ >>> /bye
75
+ Goodbye.
76
+ ```
77
+
78
+ ### Option 2: one terminal command
79
+
80
+ Paste this whole line into your terminal to clean a single sentence:
81
+
82
+ ```bash
83
+ python3 -c "from transformers import AutoModel, AutoTokenizer; t=AutoTokenizer.from_pretrained('Rybib/EDEN', trust_remote_code=True); m=AutoModel.from_pretrained('Rybib/EDEN', trust_remote_code=True).eval(); print(m.enhance(t, 'i relly wnt this to sound beter'))"
84
+ ```
85
+
86
+ ### Option 3: a Python script
87
 
88
  The lines below are Python, not terminal commands. Save them as a file such as
89
  `run.py`, then run `python3 run.py`. Do not paste them straight into the
 
94
 
95
  model_id = "Rybib/EDEN"
96
 
97
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
98
  model = AutoModel.from_pretrained(model_id, trust_remote_code=True).eval()
99
 
100
  rough = "i relly wnt this sentance to sound more profesional"
 
102
  # I really want this sentence to sound more professional.
103
  ```
104
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  The `enhance` method handles long inputs by splitting them into sentence-aware
106
  chunks, rewriting each chunk, and joining the results.
107
 
examples/try_eden.py CHANGED
@@ -1,19 +1,40 @@
1
- """Try the published EDEN model with no setup beyond pip install.
2
 
3
- This downloads the model from the Hugging Face Hub the first time it runs and
4
- caches it. After that it works offline.
5
 
6
  Usage:
7
- python try_eden.py # interactive: type text, get it fixed
8
- python try_eden.py "some rough text" # one-shot: fix the given text
9
  """
10
 
11
  import sys
12
 
13
  MODEL_ID = "Rybib/EDEN"
14
 
 
 
 
 
 
 
 
15
 
16
- def main() -> None:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  try:
18
  from transformers import AutoModel, AutoTokenizer
19
  except ImportError:
@@ -21,28 +42,41 @@ def main() -> None:
21
  print(" pip3 install torch transformers")
22
  sys.exit(1)
23
 
24
- print(f"Loading {MODEL_ID} (first run downloads about 430 MB, please wait) ...")
25
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
26
  model = AutoModel.from_pretrained(MODEL_ID, trust_remote_code=True).eval()
27
- print("Ready.\n")
 
28
 
 
 
 
 
29
  args = [a for a in sys.argv[1:] if a.strip()]
30
  if args:
31
- text = " ".join(args)
32
- print(model.enhance(tokenizer, text))
33
  return
34
 
35
- print("Type rough text and press Enter to clean it up.")
36
- print("Press Ctrl+C or Ctrl+D to quit.\n")
37
  while True:
38
  try:
39
- text = input("rough> ").strip()
40
  except (EOFError, KeyboardInterrupt):
41
- print("\nGoodbye.")
42
  return
 
43
  if not text:
44
  continue
45
- print("clean> " + model.enhance(tokenizer, text) + "\n")
 
 
 
 
 
 
 
 
46
 
47
 
48
  if __name__ == "__main__":
 
1
+ """Talk to EDEN in the terminal, similar to how Ollama works.
2
 
3
+ This downloads the published model from the Hugging Face Hub the first time it
4
+ runs and caches it. After that it works offline.
5
 
6
  Usage:
7
+ python3 try_eden.py # open the chat interface
8
+ python3 try_eden.py "some rough text" # one-shot: clean the given text
9
  """
10
 
11
  import sys
12
 
13
  MODEL_ID = "Rybib/EDEN"
14
 
15
+ # ANSI styles, used only when writing to a real terminal.
16
+ _TTY = sys.stdout.isatty()
17
+ BOLD = "\033[1m" if _TTY else ""
18
+ DIM = "\033[2m" if _TTY else ""
19
+ GREEN = "\033[32m" if _TTY else ""
20
+ CYAN = "\033[36m" if _TTY else ""
21
+ RESET = "\033[0m" if _TTY else ""
22
 
23
+ BANNER = f"""{CYAN}{BOLD}
24
+ EDEN :: Encoder Decoder Enhancement Network
25
+ {RESET}{DIM} Type or paste rough text and press Enter to clean it up.
26
+ Commands: /help show help /bye quit (Ctrl+D also quits)
27
+ {RESET}"""
28
+
29
+ HELP = f"""{DIM}
30
+ Just type or paste text, then press Enter, and EDEN rewrites it.
31
+ Commands:
32
+ /help show this help
33
+ /bye quit (so do /exit, /quit, and Ctrl+D)
34
+ {RESET}"""
35
+
36
+
37
+ def load_model():
38
  try:
39
  from transformers import AutoModel, AutoTokenizer
40
  except ImportError:
 
42
  print(" pip3 install torch transformers")
43
  sys.exit(1)
44
 
45
+ print(f"{DIM}Loading {MODEL_ID} (first run downloads about 430 MB) ...{RESET}")
46
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
47
  model = AutoModel.from_pretrained(MODEL_ID, trust_remote_code=True).eval()
48
+ return model, tokenizer
49
+
50
 
51
+ def main() -> None:
52
+ model, tokenizer = load_model()
53
+
54
+ # One-shot mode: clean the text passed as arguments and exit.
55
  args = [a for a in sys.argv[1:] if a.strip()]
56
  if args:
57
+ print(model.enhance(tokenizer, " ".join(args)))
 
58
  return
59
 
60
+ # Interactive chat mode.
61
+ print(BANNER)
62
  while True:
63
  try:
64
+ text = input(f"{GREEN}{BOLD}>>> {RESET}").strip()
65
  except (EOFError, KeyboardInterrupt):
66
+ print(f"\n{DIM}Goodbye.{RESET}")
67
  return
68
+
69
  if not text:
70
  continue
71
+ if text.lower() in {"/bye", "/exit", "/quit", "/q"}:
72
+ print(f"{DIM}Goodbye.{RESET}")
73
+ return
74
+ if text.lower() in {"/help", "/h", "/?"}:
75
+ print(HELP)
76
+ continue
77
+
78
+ cleaned = model.enhance(tokenizer, text)
79
+ print(f"{CYAN}{cleaned}{RESET}\n")
80
 
81
 
82
  if __name__ == "__main__":
examples/use_with_transformers.py CHANGED
@@ -19,7 +19,7 @@ from transformers import AutoModel, AutoTokenizer
19
  # Point this at the published model id or a local path to this repository.
20
  MODEL_ID = REPO_ROOT
21
 
22
- tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
23
  model = AutoModel.from_pretrained(MODEL_ID, trust_remote_code=True).eval()
24
 
25
  examples = [
 
19
  # Point this at the published model id or a local path to this repository.
20
  MODEL_ID = REPO_ROOT
21
 
22
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
23
  model = AutoModel.from_pretrained(MODEL_ID, trust_remote_code=True).eval()
24
 
25
  examples = [