ColeGuion commited on
Commit
f27161f
·
verified ·
1 Parent(s): 462a7e6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -10
app.py CHANGED
@@ -1,10 +1,32 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
 
3
 
4
  """
5
  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
6
  """
7
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
  def respond(
@@ -46,15 +68,9 @@ demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
48
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
- gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
- gr.Slider(
52
- minimum=0.1,
53
- maximum=1.0,
54
- value=0.95,
55
- step=0.05,
56
- label="Top-p (nucleus sampling)",
57
- ),
58
  ],
59
  )
60
 
 
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
+ #client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
9
+ client = InferenceClient("vennify/t5-base-grammar-correction")
10
+ #gr.load("models/vennify/t5-base-grammar-correction").launch()
11
+
12
+ # Load the model and tokenizer
13
+ model_name = "vennify/t5-base-grammar-correction"
14
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
15
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
16
+
17
+
18
+ # Define the function to generate corrected text
19
+ def correct_text(text, max_length, num_beams, temperature):
20
+ inputs = tokenizer.encode(text, return_tensors="pt")
21
+ outputs = model.generate(
22
+ inputs,
23
+ max_length=max_length,
24
+ num_beams=num_beams,
25
+ temperature=temperature,
26
+ early_stopping=True
27
+ )
28
+ corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
29
+ return corrected_text
30
 
31
 
32
  def respond(
 
68
  respond,
69
  additional_inputs=[
70
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
71
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
72
+ gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
73
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (nucleus sampling)"),
 
 
 
 
 
 
74
  ],
75
  )
76