enotkrutoy commited on
Commit
45060c1
1 Parent(s): 1106f76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -19
app.py CHANGED
@@ -1,11 +1,9 @@
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,23 +23,20 @@ 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
44
- """
45
  demo = gr.ChatInterface(
46
  respond,
47
  additional_inputs=[
@@ -58,6 +53,5 @@ demo = gr.ChatInterface(
58
  ],
59
  )
60
 
61
-
62
  if __name__ == "__main__":
63
  demo.launch()
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForCausalLM
 
 
 
 
 
3
 
4
+ # Load model directly
5
+ tokenizer = AutoTokenizer.from_pretrained("Leo022/Gemma_QA_For_Telegram_Bot")
6
+ model = AutoModelForCausalLM.from_pretrained("Leo022/Gemma_QA_For_Telegram_Bot")
7
 
8
  def respond(
9
  message,
 
23
 
24
  messages.append({"role": "user", "content": message})
25
 
26
+ input_ids = tokenizer.encode(messages, return_tensors="pt")
27
 
28
+ output = model.generate(
29
+ input_ids,
30
+ max_length=max_tokens,
 
31
  temperature=temperature,
32
  top_p=top_p,
33
+ do_sample=True,
34
+ )
35
+
36
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
37
 
38
+ return response
 
39
 
 
 
 
40
  demo = gr.ChatInterface(
41
  respond,
42
  additional_inputs=[
 
53
  ],
54
  )
55
 
 
56
  if __name__ == "__main__":
57
  demo.launch()