ColeGuion commited on
Commit
100aaa7
1 Parent(s): 5bdcf36

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +2 -9
app.py CHANGED
@@ -1,14 +1,9 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
4
 
5
- """
6
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
7
- """
8
  # Load the model and tokenizer
9
- model_name = "vennify/t5-base-grammar-correction"
10
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
11
- tokenizer = AutoTokenizer.from_pretrained(model_name)
12
 
13
  def correct_text(text, max_length, max_new_tokens, min_length, num_beams, temperature, top_p):
14
  inputs = tokenizer.encode("grammar: " + text, return_tensors="pt")
@@ -37,7 +32,6 @@ def correct_text(text, max_length, max_new_tokens, min_length, num_beams, temper
37
  corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
38
  return corrected_text
39
 
40
-
41
  def respond(message, history, max_length, min_length, max_new_tokens, num_beams, temperature, top_p):
42
  response = correct_text(message, max_length, max_new_tokens, min_length, num_beams, temperature, top_p)
43
  yield response
@@ -48,7 +42,6 @@ For information on how to customize the ChatInterface, peruse the gradio docs: h
48
  demo = gr.ChatInterface(
49
  respond,
50
  additional_inputs=[
51
- #gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
52
  gr.Slider(minimum=1, maximum=256, value=100, step=1, label="Max Length"),
53
  gr.Slider(minimum=1, maximum=256, value=0, step=1, label="Min Length"),
54
  gr.Slider(minimum=0, maximum=256, value=0, step=1, label="Max New Tokens (optional)"),
 
1
  import gradio as gr
 
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
 
 
 
 
4
  # Load the model and tokenizer
5
+ model = AutoModelForSeq2SeqLM.from_pretrained("vennify/t5-base-grammar-correction")
6
+ tokenizer = AutoTokenizer.from_pretrained("vennify/t5-base-grammar-correction")
 
7
 
8
  def correct_text(text, max_length, max_new_tokens, min_length, num_beams, temperature, top_p):
9
  inputs = tokenizer.encode("grammar: " + text, return_tensors="pt")
 
32
  corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
33
  return corrected_text
34
 
 
35
  def respond(message, history, max_length, min_length, max_new_tokens, num_beams, temperature, top_p):
36
  response = correct_text(message, max_length, max_new_tokens, min_length, num_beams, temperature, top_p)
37
  yield response
 
42
  demo = gr.ChatInterface(
43
  respond,
44
  additional_inputs=[
 
45
  gr.Slider(minimum=1, maximum=256, value=100, step=1, label="Max Length"),
46
  gr.Slider(minimum=1, maximum=256, value=0, step=1, label="Min Length"),
47
  gr.Slider(minimum=0, maximum=256, value=0, step=1, label="Max New Tokens (optional)"),