Omnibus commited on
Commit
bdd660d
1 Parent(s): 58e4560

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -9
app.py CHANGED
@@ -16,11 +16,17 @@ def format_prompt(message, history):
16
  prompt += f"[INST] {message} [/INST]"
17
  return prompt
18
 
19
- def compress_history(history,temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
 
 
 
 
 
 
20
  formatted_prompt=f"{COMPRESS_HISTORY.format(history=history)}"
21
  generate_kwargs = dict(
22
  temperature=temperature,
23
- max_new_tokens=max_new_tokens,
24
  top_p=top_p,
25
  repetition_penalty=repetition_penalty,
26
  do_sample=True,
@@ -35,9 +41,7 @@ def compress_history(history,temperature=0.9, max_new_tokens=256, top_p=0.95, re
35
 
36
  MAX_HISTORY=100
37
 
38
- def generate(
39
- prompt, history, system_prompt, temperature=0.9, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0,
40
- ):
41
  temperature = float(temperature)
42
  if temperature < 1e-2:
43
  temperature = 1e-2
@@ -60,14 +64,14 @@ def generate(
60
  cnt+=len(l.split("\n"))
61
  print(f'cnt:: {cnt}')
62
  if cnt > MAX_HISTORY:
63
- history = compress_history(history, temperature, max_new_tokens, top_p, repetition_penalty)
64
  formatted_prompt = format_prompt(f"{GAME_MASTER.format(history=history)}, {prompt}", history)
65
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
66
  output = ""
67
 
68
  for response in stream:
69
  output += response.token.text
70
- yield output
71
 
72
  lines = output.strip().strip("\n").split("\n")
73
  #history=""
@@ -82,7 +86,7 @@ def generate(
82
  print(line)
83
  if line.startswith("5. "):
84
  print(line)
85
- return output
86
 
87
 
88
  additional_inputs=[
@@ -129,6 +133,36 @@ additional_inputs=[
129
  )
130
  ]
131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
  examples=[["Start the Game", None, None, None, None, None, ],
133
  ["Start a Game based in the year 1322", None, None, None, None, None,],
134
  ]
@@ -140,4 +174,7 @@ gr.ChatInterface(
140
  title="Mixtral RPG Game Master",
141
  examples=examples,
142
  concurrency_limit=20,
143
- ).launch(share=True,show_api=True)
 
 
 
 
16
  prompt += f"[INST] {message} [/INST]"
17
  return prompt
18
 
19
+
20
+ temperature=0.9
21
+ top_p=0.95
22
+ repetition_penalty=1.0
23
+
24
+
25
+ def compress_history(history):
26
  formatted_prompt=f"{COMPRESS_HISTORY.format(history=history)}"
27
  generate_kwargs = dict(
28
  temperature=temperature,
29
+ max_new_tokens=1024,
30
  top_p=top_p,
31
  repetition_penalty=repetition_penalty,
32
  do_sample=True,
 
41
 
42
  MAX_HISTORY=100
43
 
44
+ def generate(prompt, history,max_new_tokens):
 
 
45
  temperature = float(temperature)
46
  if temperature < 1e-2:
47
  temperature = 1e-2
 
64
  cnt+=len(l.split("\n"))
65
  print(f'cnt:: {cnt}')
66
  if cnt > MAX_HISTORY:
67
+ history = compress_history(str(history), temperature, max_new_tokens, top_p, repetition_penalty)
68
  formatted_prompt = format_prompt(f"{GAME_MASTER.format(history=history)}, {prompt}", history)
69
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
70
  output = ""
71
 
72
  for response in stream:
73
  output += response.token.text
74
+ yield "",[(prompt,output)]
75
 
76
  lines = output.strip().strip("\n").split("\n")
77
  #history=""
 
86
  print(line)
87
  if line.startswith("5. "):
88
  print(line)
89
+ return "",[(prompt,output)]
90
 
91
 
92
  additional_inputs=[
 
133
  )
134
  ]
135
 
136
+
137
+
138
+ with gr.Blocks() as app:
139
+ gr.HTML("""<center><h1>Mixtral 8x7B RPG</h1><h3>Role Playing Game Master</h3>""")
140
+ chatbot = gr.Chatbot(label="Mixtral 8x7B Chatbot",show_copy_button=True)
141
+ with gr.Row():
142
+ with gr.Column(scale=3):
143
+ prompt=gr.Textbox(label = "Prompt")
144
+ with gr.Column(scale=1):
145
+ button=gr.Button()
146
+
147
+ #models_dd=gr.Dropdown(choices=[m for m in return_list],interactive=True)
148
+ with gr.Row():
149
+ stop_button=gr.Button("Stop")
150
+ clear_btn = gr.Button("Clear")
151
+ with gr.Row():
152
+ tokens=additional_inputs[2]
153
+ json_out=gr.JSON()
154
+ e_box=gr.Textbox()
155
+ #text=gr.JSON()
156
+ #inp_query.change(search_models,inp_query,models_dd)
157
+ #test_b=test_btn.click(itt,url,e_box)
158
+ clear_btn.click(clear_fn,None,[prompt,chatbot])
159
+ go=button.click(generate,[prompt,chatbot,tokens],[prompt,chatbot])
160
+ stop_button.click(None,None,None,cancels=[go])
161
+ app.launch(show_api=False)
162
+
163
+
164
+
165
+ '''
166
  examples=[["Start the Game", None, None, None, None, None, ],
167
  ["Start a Game based in the year 1322", None, None, None, None, None,],
168
  ]
 
174
  title="Mixtral RPG Game Master",
175
  examples=examples,
176
  concurrency_limit=20,
177
+ ).launch(share=True,show_api=True)
178
+ '''
179
+
180
+