Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,9 +18,9 @@ def format_prompt(history):
|
|
18 |
|
19 |
def generate(prompt, history=[], temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
20 |
# Add the first user message to history if it's not already there
|
21 |
-
if not history:
|
22 |
-
history
|
23 |
-
|
24 |
temperature = float(temperature)
|
25 |
if temperature < 1e-2:
|
26 |
temperature = 1e-2
|
@@ -43,26 +43,30 @@ def generate(prompt, history=[], temperature=0.2, max_new_tokens=256, top_p=0.95
|
|
43 |
output = ""
|
44 |
for response in stream:
|
45 |
output += response.token.text
|
46 |
-
|
47 |
# Adding the latest prompts and responses to history
|
48 |
-
|
|
|
49 |
|
50 |
return output, history # Pass the updated history back to the interface
|
51 |
|
52 |
# Setting up the Chat Interface
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
56 |
|
57 |
demo = gr.Interface(
|
58 |
-
fn=generate,
|
59 |
-
inputs=
|
60 |
-
outputs=
|
61 |
title="Mixtral 8x7b Chat",
|
62 |
theme="default",
|
63 |
-
initial_state=[(first_user_message, "")], # Initialize the history with the first message
|
64 |
allow_screenshot=False,
|
65 |
-
allow_flagging="never"
|
|
|
|
|
66 |
)
|
67 |
|
68 |
demo.launch()
|
|
|
18 |
|
19 |
def generate(prompt, history=[], temperature=0.2, max_new_tokens=256, top_p=0.95, repetition_penalty=1.0):
|
20 |
# Add the first user message to history if it's not already there
|
21 |
+
if not history and prompt:
|
22 |
+
history = [(first_user_message, "")]
|
23 |
+
|
24 |
temperature = float(temperature)
|
25 |
if temperature < 1e-2:
|
26 |
temperature = 1e-2
|
|
|
43 |
output = ""
|
44 |
for response in stream:
|
45 |
output += response.token.text
|
46 |
+
|
47 |
# Adding the latest prompts and responses to history
|
48 |
+
if prompt: # to avoid adding empty strings to history
|
49 |
+
history.append((prompt, output.strip()))
|
50 |
|
51 |
return output, history # Pass the updated history back to the interface
|
52 |
|
53 |
# Setting up the Chat Interface
|
54 |
+
inputs=[gr.Textbox(label="User Input", lines=2, placeholder="Enter your message here..."), gr.State()]
|
55 |
+
outputs=[gr.Textbox(label="AI Response", lines=2, placeholder="AI will respond here..."), gr.State()]
|
56 |
+
|
57 |
+
def reset():
|
58 |
+
return "", [(first_user_message, "")]
|
59 |
|
60 |
demo = gr.Interface(
|
61 |
+
fn=generate,
|
62 |
+
inputs=inputs,
|
63 |
+
outputs=outputs,
|
64 |
title="Mixtral 8x7b Chat",
|
65 |
theme="default",
|
|
|
66 |
allow_screenshot=False,
|
67 |
+
allow_flagging="never",
|
68 |
+
live=True,
|
69 |
+
event_handlers=[("load", reset)]
|
70 |
)
|
71 |
|
72 |
demo.launch()
|