Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -82,45 +82,45 @@ def load_models(inp):
|
|
82 |
VERBOSE=False
|
83 |
|
84 |
|
85 |
-
def chat_inf(
|
86 |
#token max=8192
|
87 |
-
model_n=models[model_name]
|
88 |
-
print(model_state)
|
89 |
hist_len=0
|
90 |
client=model_state
|
91 |
-
if not history:
|
92 |
-
|
93 |
-
|
94 |
-
if not memory:
|
95 |
-
|
96 |
-
|
97 |
-
if memory:
|
98 |
-
|
99 |
-
|
100 |
-
in_len=len(system_prompt+prompt)+hist_len
|
101 |
-
|
102 |
-
if (in_len+tokens) > 8000:
|
103 |
-
|
104 |
-
|
105 |
-
else:
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
|
125 |
|
126 |
def get_screenshot(chat: list,height=5000,width=600,chatblock=[],theme="light",wait=3000,header=True):
|
@@ -147,7 +147,10 @@ with gr.Blocks() as app:
|
|
147 |
model_state=gr.State()
|
148 |
memory=gr.State()
|
149 |
gr.HTML("""<center><h1 style='font-size:xx-large;'>Huggingface Hub InferenceClient</h1><br><h3>Chatbot's</h3></center>""")
|
150 |
-
chat_b = gr.Chatbot(height=500)
|
|
|
|
|
|
|
151 |
with gr.Group():
|
152 |
with gr.Row():
|
153 |
with gr.Column(scale=3):
|
@@ -187,7 +190,9 @@ with gr.Blocks() as app:
|
|
187 |
theme=gr.Radio(label="Theme", choices=["light","dark"],value="light")
|
188 |
chatblock=gr.Dropdown(label="Chatblocks",info="Choose specific blocks of chat",choices=[c for c in range(1,40)],multiselect=True)
|
189 |
test_json=gr.JSON(label="Test Output")
|
190 |
-
test_btn.click(test_models,None,test_json)
|
|
|
|
|
191 |
|
192 |
client_choice.change(load_models,client_choice,[chat_b,custom_prompt,model_state])
|
193 |
app.load(load_models,client_choice,[chat_b,custom_prompt,model_state])
|
|
|
82 |
VERBOSE=False
|
83 |
|
84 |
|
85 |
+
def chat_inf(prompt,model_state,model_name,seed,temp,tokens,top_p,rep_p,chat_mem,cust_p):
|
86 |
#token max=8192
|
87 |
+
#model_n=models[model_name]
|
88 |
+
#print(model_state)
|
89 |
hist_len=0
|
90 |
client=model_state
|
91 |
+
#if not history:
|
92 |
+
# history = []
|
93 |
+
# hist_len=0
|
94 |
+
#if not memory:
|
95 |
+
# memory = []
|
96 |
+
# mem_len=0
|
97 |
+
#if memory:
|
98 |
+
# for ea in memory[0-chat_mem:]:
|
99 |
+
# hist_len+=len(str(ea))
|
100 |
+
#in_len=len(system_prompt+prompt)+hist_len
|
101 |
+
|
102 |
+
#if (in_len+tokens) > 8000:
|
103 |
+
# history.append((prompt,"Wait, that's too many tokens, please reduce the 'Chat Memory' value, or reduce the 'Max new tokens' value"))
|
104 |
+
# yield history,memory
|
105 |
+
#else:
|
106 |
+
generate_kwargs = dict(
|
107 |
+
temperature=temp,
|
108 |
+
max_new_tokens=tokens,
|
109 |
+
top_p=top_p,
|
110 |
+
repetition_penalty=rep_p,
|
111 |
+
do_sample=True,
|
112 |
+
seed=seed,
|
113 |
+
)
|
114 |
+
|
115 |
+
stream = client.text_generation(prompt, **generate_kwargs, stream=True, details=True, return_full_text=True)
|
116 |
+
output = prompt
|
117 |
+
for response in stream:
|
118 |
+
output += response.token.text
|
119 |
+
yield output
|
120 |
+
#history.append((prompt,output))
|
121 |
+
#memory.append((prompt,output))
|
122 |
+
yield output
|
123 |
+
|
124 |
|
125 |
|
126 |
def get_screenshot(chat: list,height=5000,width=600,chatblock=[],theme="light",wait=3000,header=True):
|
|
|
147 |
model_state=gr.State()
|
148 |
memory=gr.State()
|
149 |
gr.HTML("""<center><h1 style='font-size:xx-large;'>Huggingface Hub InferenceClient</h1><br><h3>Chatbot's</h3></center>""")
|
150 |
+
#chat_b = gr.Chatbot(height=500)
|
151 |
+
chat_b = gr.Textbox(lines=10)
|
152 |
+
|
153 |
+
|
154 |
with gr.Group():
|
155 |
with gr.Row():
|
156 |
with gr.Column(scale=3):
|
|
|
190 |
theme=gr.Radio(label="Theme", choices=["light","dark"],value="light")
|
191 |
chatblock=gr.Dropdown(label="Chatblocks",info="Choose specific blocks of chat",choices=[c for c in range(1,40)],multiselect=True)
|
192 |
test_json=gr.JSON(label="Test Output")
|
193 |
+
#test_btn.click(test_models,None,test_json)
|
194 |
+
|
195 |
+
c_comp=chat_b.change(chat_inf,[chat_b,model_state,client_choice,seed,temp,tokens,top_p,rep_p,chat_mem,custom_prompt],[chat_b,memory]))
|
196 |
|
197 |
client_choice.change(load_models,client_choice,[chat_b,custom_prompt,model_state])
|
198 |
app.load(load_models,client_choice,[chat_b,custom_prompt,model_state])
|