basit123796 commited on
Commit
3d13b76
·
verified ·
1 Parent(s): b690674

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -17
app.py CHANGED
@@ -1,7 +1,6 @@
1
  import gradio as gr
2
  from gradio_client import Client
3
  from huggingface_hub import InferenceClient
4
- import random
5
 
6
  ss_client = Client("https://omnibus-html-image-current-tab.hf.space/")
7
 
@@ -38,7 +37,7 @@ def format_prompt(message, history):
38
  prompt += message
39
  return prompt
40
 
41
- def chat_inf(system_prompt,prompt,history,memory,client_choice,seed,temp,tokens,top_p,rep_p,chat_mem):
42
  hist_len=0
43
  client=clients[int(client_choice)-1]
44
  if not history:
@@ -50,7 +49,7 @@ def chat_inf(system_prompt,prompt,history,memory,client_choice,seed,temp,tokens,
50
  if memory:
51
  for ea in memory[0-chat_mem:]:
52
  hist_len+=len(str(ea))
53
- in_len=len(system_prompt+prompt)+hist_len
54
 
55
  if (in_len+tokens) > 8000:
56
  history.append((prompt,"Wait, that's too many tokens, please reduce the 'Chat Memory' value, or reduce the 'Max new tokens' value"))
@@ -62,9 +61,8 @@ def chat_inf(system_prompt,prompt,history,memory,client_choice,seed,temp,tokens,
62
  top_p=top_p,
63
  repetition_penalty=rep_p,
64
  do_sample=True,
65
- seed=seed,
66
  )
67
- formatted_prompt = format_prompt(f"{system_prompt}, {prompt}", memory[0-chat_mem:])
68
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
69
  output = ""
70
  for response in stream:
@@ -88,14 +86,7 @@ def get_screenshot(chat: list,height=5000,width=600,chatblock=[],theme="light",w
88
 
89
  def clear_fn():
90
  return None,None,None,None
91
- rand_val=random.randint(1,1111111111111111)
92
 
93
- def check_rand(inp,val):
94
- if inp==True:
95
- return random.randint(1,1111111111111111)
96
- else:
97
- return int(val)
98
-
99
  with gr.Blocks() as app:
100
  memory=gr.State()
101
  chat_b = gr.Chatbot(height=500)
@@ -106,10 +97,8 @@ with gr.Blocks() as app:
106
  btn = gr.Button("Chat")
107
  with gr.Column(scale=1):
108
  with gr.Group():
109
- rand = gr.Checkbox(label="Random Seed", value=True)
110
- seed=gr.Slider(label="Seed", minimum=1, maximum=1111111111111111,step=1, value=rand_val)
111
- tokens = gr.Slider(label="Max new tokens",value=1600,minimum=0,maximum=8000,step=64,interactive=True, visible=True,info="The maximum number of tokens")
112
  temp=gr.Slider(label="Temperature",step=0.01, minimum=0.01, maximum=1.0, value=0.49)
 
113
  top_p=gr.Slider(label="Top-P",step=0.01, minimum=0.01, maximum=1.0, value=0.49)
114
  rep_p=gr.Slider(label="Repetition Penalty",step=0.01, minimum=0.1, maximum=2.0, value=0.99)
115
  chat_mem=gr.Number(label="Chat Memory", info="Number of previous chats to retain",value=4)
@@ -118,7 +107,7 @@ with gr.Blocks() as app:
118
  client_choice.change(load_models,client_choice,[chat_b])
119
  app.load(load_models,client_choice,[chat_b])
120
 
121
- chat_sub=inp.submit(check_rand,[rand,seed],seed).then(chat_inf,[inp,inp,chat_b,memory,client_choice,seed,temp,tokens,top_p,rep_p,chat_mem],[chat_b,memory])
122
- go=btn.click(check_rand,[rand,seed],seed).then(chat_inf,[inp,inp,chat_b,memory,client_choice,seed,temp,tokens,top_p,rep_p,chat_mem],[chat_b,memory])
123
 
124
  app.queue(default_concurrency_limit=10).launch()
 
1
  import gradio as gr
2
  from gradio_client import Client
3
  from huggingface_hub import InferenceClient
 
4
 
5
  ss_client = Client("https://omnibus-html-image-current-tab.hf.space/")
6
 
 
37
  prompt += message
38
  return prompt
39
 
40
+ def chat_inf(prompt,history,memory,client_choice,temp,tokens,top_p,rep_p,chat_mem):
41
  hist_len=0
42
  client=clients[int(client_choice)-1]
43
  if not history:
 
49
  if memory:
50
  for ea in memory[0-chat_mem:]:
51
  hist_len+=len(str(ea))
52
+ in_len=len(prompt)+hist_len
53
 
54
  if (in_len+tokens) > 8000:
55
  history.append((prompt,"Wait, that's too many tokens, please reduce the 'Chat Memory' value, or reduce the 'Max new tokens' value"))
 
61
  top_p=top_p,
62
  repetition_penalty=rep_p,
63
  do_sample=True,
 
64
  )
65
+ formatted_prompt = format_prompt(prompt, memory[0-chat_mem:])
66
  stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
67
  output = ""
68
  for response in stream:
 
86
 
87
  def clear_fn():
88
  return None,None,None,None
 
89
 
 
 
 
 
 
 
90
  with gr.Blocks() as app:
91
  memory=gr.State()
92
  chat_b = gr.Chatbot(height=500)
 
97
  btn = gr.Button("Chat")
98
  with gr.Column(scale=1):
99
  with gr.Group():
 
 
 
100
  temp=gr.Slider(label="Temperature",step=0.01, minimum=0.01, maximum=1.0, value=0.49)
101
+ tokens = gr.Slider(label="Max new tokens",value=1600,minimum=0,maximum=8000,step=64,interactive=True, visible=True,info="The maximum number of tokens")
102
  top_p=gr.Slider(label="Top-P",step=0.01, minimum=0.01, maximum=1.0, value=0.49)
103
  rep_p=gr.Slider(label="Repetition Penalty",step=0.01, minimum=0.1, maximum=2.0, value=0.99)
104
  chat_mem=gr.Number(label="Chat Memory", info="Number of previous chats to retain",value=4)
 
107
  client_choice.change(load_models,client_choice,[chat_b])
108
  app.load(load_models,client_choice,[chat_b])
109
 
110
+ chat_sub=inp.submit().then(chat_inf,[inp,chat_b,memory,client_choice,temp,tokens,top_p,rep_p,chat_mem],[chat_b,memory])
111
+ go=btn.click().then(chat_inf,[inp,chat_b,memory,client_choice,temp,tokens,top_p,rep_p,chat_mem],[chat_b,memory])
112
 
113
  app.queue(default_concurrency_limit=10).launch()