FlipTip commited on
Commit
dd823b4
1 Parent(s): 0503e8f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -13
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.append((first_user_message, ""))
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
- history.append((prompt, output))
 
49
 
50
  return output, history # Pass the updated history back to the interface
51
 
52
  # Setting up the Chat Interface
53
- mychatbot = gr.Chatbot(
54
- avatar_images=["./user.png", "./botm.png"], bubble_full_width=False, show_label=False, show_copy_button=True, likeable=True,
55
- )
 
 
56
 
57
  demo = gr.Interface(
58
- fn=generate,
59
- inputs=[gr.Textbox(label="User Input", lines=2, placeholder="Enter your message here..."), gr.State()],
60
- outputs=[gr.Textbox(label="AI Response", lines=2, placeholder="AI will respond here..."), gr.State()],
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()