peter szemraj commited on
Commit
e770698
1 Parent(s): 5c43041

:construction: continue removing gramformer stuff

Browse files
Files changed (1) hide show
  1. app.py +3 -31
app.py CHANGED
@@ -12,8 +12,6 @@ import time
12
  import warnings
13
  from pathlib import Path
14
  from cleantext import clean
15
- from transformers import pipeline
16
- from datetime import datetime
17
  from ai_single_response import query_gpt_model
18
  from utils import correct_phrase_load
19
 
@@ -24,30 +22,6 @@ cwd = Path.cwd()
24
  my_cwd = str(cwd.resolve()) # string so it can be passed to os.path() objects
25
 
26
 
27
- def gramformer_correct(corrector, qphrase: str):
28
- """
29
- gramformer_correct - correct a string using a text2textgen pipeline model from transformers
30
-
31
- Args:
32
- corrector (transformers.pipeline): [transformers pipeline object, already created w/ relevant model]
33
- qphrase (str): [text to be corrected]
34
-
35
- Returns:
36
- [str]: [corrected text]
37
- """
38
-
39
- try:
40
- corrected = corrector(
41
- clean(qphrase), return_text=True, clean_up_tokenization_spaces=True
42
- )
43
- return corrected[0]["generated_text"]
44
- except:
45
- print("NOTE - failed to correct with gramformer")
46
- return clean(
47
- qphrase
48
- ) # fallback is to return the cleaned up version of the message
49
-
50
-
51
  def ask_gpt(message: str):
52
  """
53
  ask_gpt - queries the relevant model with a prompt message and returns the response.
@@ -107,7 +81,6 @@ if __name__ == "__main__":
107
  default_model = "Ballpark-Trivia-L"
108
  model_loc = cwd.parent / default_model
109
  model_loc = str(model_loc.resolve())
110
- gram_model = "prithivida/grammar_error_correcter_v1"
111
 
112
  # init items for the pipeline
113
  iface = gr.Interface(
@@ -115,8 +88,9 @@ if __name__ == "__main__":
115
  inputs=["text"],
116
  outputs="html",
117
  title=f"Ballpark Trivia: {default_model} Model",
118
- description=f"Are you frequently asked google-able Trivia questions and annoyed by it? Well, this is the app for you! Ballpark Trivia Bot answers any trivia question with something that sounds plausible but is probably not 100% correct. \n\n One might say.. the answers are in the right ballpark. Further details can be found in the [model card](https://huggingface.co/pszemraj/Ballpark-Trivia-L), and there is also an XL-size model.",
119
- article="**Important Notes & About:**\n"
 
120
  "1. the model can take up to 60 seconds to respond sometimes, patience is a virtue.\n"
121
  "2. the model started from a pretrained checkpoint, and was trained on several different datasets. Anything it says be fact-checked before being regarded as a true statement.\n ",
122
  css="""
@@ -137,8 +111,6 @@ if __name__ == "__main__":
137
  theme="darkhuggingface",
138
  )
139
 
140
- corrector = pipeline("text2text-generation", model=gram_model, device=-1)
141
- print("Finished loading the gramformer model - ", datetime.now())
142
  print(f"using model stored here: \n {model_loc} \n")
143
 
144
  # launch the gradio interface and start the server
 
12
  import warnings
13
  from pathlib import Path
14
  from cleantext import clean
 
 
15
  from ai_single_response import query_gpt_model
16
  from utils import correct_phrase_load
17
 
 
22
  my_cwd = str(cwd.resolve()) # string so it can be passed to os.path() objects
23
 
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  def ask_gpt(message: str):
26
  """
27
  ask_gpt - queries the relevant model with a prompt message and returns the response.
 
81
  default_model = "Ballpark-Trivia-L"
82
  model_loc = cwd.parent / default_model
83
  model_loc = str(model_loc.resolve())
 
84
 
85
  # init items for the pipeline
86
  iface = gr.Interface(
 
88
  inputs=["text"],
89
  outputs="html",
90
  title=f"Ballpark Trivia: {default_model} Model",
91
+ description=f"Are you frequently asked google-able Trivia questions and annoyed by it? Well, this is the app for you! Ballpark Trivia Bot answers any trivia question with something that sounds plausible but is probably not 100% correct. \n\n One might say.. the answers are in the right ballpark.",
92
+ article="Further details can be found in the[model card](https: // huggingface.co/pszemraj/Ballpark-Trivia-L), and there is also an XL-size model.\n\n"
93
+ "**Important Notes & About:**\n"
94
  "1. the model can take up to 60 seconds to respond sometimes, patience is a virtue.\n"
95
  "2. the model started from a pretrained checkpoint, and was trained on several different datasets. Anything it says be fact-checked before being regarded as a true statement.\n ",
96
  css="""
 
111
  theme="darkhuggingface",
112
  )
113
 
 
 
114
  print(f"using model stored here: \n {model_loc} \n")
115
 
116
  # launch the gradio interface and start the server