john commited on
Commit
837474e
1 Parent(s): b96b830

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -23,7 +23,7 @@ if __name__ == "__main__":
23
  print(f"Number of threads available to the current process: {num_threads}")
24
  url = 'https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q2_K.bin'
25
  filename = wget.download(url)
26
- llm2 = Llama(model_path=filename, seed=random.randint(1, 2**31), lora_path="ggml-adapter-model.bin")
27
  filename = wget.download(url)
28
  theme = gr.themes.Soft(
29
  primary_hue=gr.themes.Color("#ededed", "#fee2e2", "#fecaca", "#fca5a5", "#f87171", "#ef4444", "#dc2626", "#b91c1c", "#991b1b", "#7f1d1d", "#6c1e1e"),
@@ -33,17 +33,11 @@ title = """<h1 align="center">Chat with awesome LLAMA 2 CHAT model!</h1><br>"""
33
  with gr.Blocks(theme=theme) as demo:
34
  gr.HTML(title)
35
  gr.HTML("This model is awesome for its size! It is only 20th the size of Chatgpt but is still decent for chatting. However like all models, LLAMA-2-CHAT can hallucinate and provide incorrect information.")
36
- chatbot = gr.Chatbot()
37
- msg = gr.Textbox()
38
- clear = gr.ClearButton([msg, chatbot])
39
  #instruction = gr.Textbox(label="Instruction", placeholder=)
40
-
41
- def user(user_message, history):
42
- return gr.update(value="", interactive=True), history + [[user_message, None]]
43
-
44
- def bot(history):
45
- #instruction = history[-1][1] or ""
46
- user_message = history[-1][0]
47
  #token1 = llm.tokenize(b"### Instruction: ")
48
  #token2 = llm.tokenize(instruction.encode())
49
  #token3 = llm2.tokenize(b"USER: ")
@@ -53,21 +47,21 @@ with gr.Blocks(theme=theme) as demo:
53
  history[-1][1] = ""
54
  count = 0
55
  output = ""
 
56
  for token in llm2.generate(tokens, top_k=50, top_p=0.73, temp=0.72, repeat_penalty=1.1):
57
  text = llm2.detokenize([token])
58
- output += text.decode()
59
  count += 1
60
  if count >= 500 or (token == llm2.token_eos()):
61
  break
62
- history[-1][1] += text.decode()
63
- yield history
64
-
65
- response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then(
66
- bot, chatbot, chatbot
67
- )
68
- response.then(lambda: gr.update(interactive=True), None, [msg], queue=False)
69
  gr.HTML("Thanks for checking out this app!")
70
-
 
 
 
 
71
  demo.queue()
72
  demo.launch(debug=True)
73
 
 
23
  print(f"Number of threads available to the current process: {num_threads}")
24
  url = 'https://huggingface.co/TheBloke/Llama-2-7B-Chat-GGML/resolve/main/llama-2-7b-chat.ggmlv3.q2_K.bin'
25
  filename = wget.download(url)
26
+ llm2 = Llama(model_path=filename, seed=random.randint(1, 2**31))
27
  filename = wget.download(url)
28
  theme = gr.themes.Soft(
29
  primary_hue=gr.themes.Color("#ededed", "#fee2e2", "#fecaca", "#fca5a5", "#f87171", "#ef4444", "#dc2626", "#b91c1c", "#991b1b", "#7f1d1d", "#6c1e1e"),
 
33
  with gr.Blocks(theme=theme) as demo:
34
  gr.HTML(title)
35
  gr.HTML("This model is awesome for its size! It is only 20th the size of Chatgpt but is still decent for chatting. However like all models, LLAMA-2-CHAT can hallucinate and provide incorrect information.")
36
+ #chatbot = gr.Chatbot()
37
+ #msg = gr.Textbox()
38
+ #clear = gr.ClearButton([msg, chatbot])
39
  #instruction = gr.Textbox(label="Instruction", placeholder=)
40
+ def bot(user_message):
 
 
 
 
 
 
41
  #token1 = llm.tokenize(b"### Instruction: ")
42
  #token2 = llm.tokenize(instruction.encode())
43
  #token3 = llm2.tokenize(b"USER: ")
 
47
  history[-1][1] = ""
48
  count = 0
49
  output = ""
50
+ outputs = ""
51
  for token in llm2.generate(tokens, top_k=50, top_p=0.73, temp=0.72, repeat_penalty=1.1):
52
  text = llm2.detokenize([token])
53
+ outputs += text.decode()
54
  count += 1
55
  if count >= 500 or (token == llm2.token_eos()):
56
  break
57
+ output += text.decode()
58
+ yield output
 
 
 
 
 
59
  gr.HTML("Thanks for checking out this app!")
60
+ gr.Button("Answer").click(
61
+ fn=bot,
62
+ inputs=gr.Textbox()
63
+ outputs=gr.Textbox()
64
+ )
65
  demo.queue()
66
  demo.launch(debug=True)
67