traversaal-ai commited on
Commit
418756d
1 Parent(s): 216d6da

Update run.py

Browse files
Files changed (1) hide show
  1. run.py +21 -2
run.py CHANGED
@@ -2,6 +2,26 @@ import gradio as gr
2
  import random
3
  import time
4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  with gr.Blocks() as demo:
6
  chatbot = gr.Chatbot()
7
  msg = gr.Textbox()
@@ -11,11 +31,10 @@ with gr.Blocks() as demo:
11
  return "", history + [[user_message, None]]
12
 
13
  def bot(history):
14
- bot_message = random.choice(["How are you?", "I love you", "I'm very hungry"])
15
  history[-1][1] = ""
16
  for character in bot_message:
17
  history[-1][1] += character
18
- time.sleep(0.05)
19
  yield history
20
 
21
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
 
2
  import random
3
  import time
4
 
5
+ endpoint_url = "https://ko60a2m26ylqgri6.us-east-1.aws.endpoints.huggingface.cloud"
6
+
7
+
8
+ # Streaming Client
9
+ client = InferenceClient(endpoint_url, token=hf_token)
10
+
11
+ # generation parameter
12
+ gen_kwargs = dict(
13
+ max_new_tokens=1024,
14
+ top_k=30,
15
+ top_p=0.9,
16
+ temperature=0.2,
17
+ repetition_penalty=1.05, #1.02
18
+ stop=["\nUser:", "<|endoftext|>", "</s>"],
19
+ )
20
+ # prompt
21
+ # prompt = "What can you do in Nuremberg, Germany? Give me 3 Tips"
22
+
23
+
24
+
25
  with gr.Blocks() as demo:
26
  chatbot = gr.Chatbot()
27
  msg = gr.Textbox()
 
31
  return "", history + [[user_message, None]]
32
 
33
  def bot(history):
34
+ bot_message = client.text_generation(history, stream=True, details=True, **gen_kwargs)
35
  history[-1][1] = ""
36
  for character in bot_message:
37
  history[-1][1] += character
 
38
  yield history
39
 
40
  msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(