paulpall commited on
Commit
c81c814
·
verified ·
1 Parent(s): d6afc96

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -12
app.py CHANGED
@@ -1,11 +1,16 @@
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(
11
  message,
@@ -25,19 +30,14 @@ def respond(
25
 
26
  messages.append({"role": "user", "content": message})
27
 
28
- response = ""
 
 
 
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message.choices[0].delta.content
38
 
39
- response += token
40
- yield response
41
 
42
  """
43
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
@@ -58,6 +58,5 @@ demo = gr.ChatInterface(
58
  ],
59
  )
60
 
61
-
62
  if __name__ == "__main__":
63
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
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
 
10
+ # Load Model
11
+ model_directory = 'paulpall/GEC_Estonian_OPUS-MT'
12
+ tokenizer = AutoTokenizer.from_pretrained(model_directory)
13
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_directory)
14
 
15
  def respond(
16
  message,
 
30
 
31
  messages.append({"role": "user", "content": message})
32
 
33
+ # Generate corrected sentence
34
+ input_ids = tokenizer.encode(message, padding='max_length', truncation=True, max_length=128, return_tensors='pt')
35
+ output_ids = model.generate(input_ids=input_ids.to(model.device))
36
+ output_sentence = tokenizer.decode(output_ids[0], skip_special_tokens=True).replace(r"▁",r" ")
37
 
38
+ response = output_sentence
 
 
 
 
 
 
 
39
 
40
+ yield response
 
41
 
42
  """
43
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
 
58
  ],
59
  )
60
 
 
61
  if __name__ == "__main__":
62
  demo.launch()