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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -26,4 +26,43 @@ def generate(prompt, history=[], temperature=0.2, max_new_tokens=256, top_p=0.95
26
  temperature = 1e-2
27
  top_p = float(top_p)
28
 
29
- generate_kwargs
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  temperature = 1e-2
27
  top_p = float(top_p)
28
 
29
+ generate_kwargs = dict(
30
+ temperature=temperature,
31
+ max_new_tokens=max_new_tokens,
32
+ top_p=top_p,
33
+ repetition_penalty=repetition_penalty,
34
+ do_sample=True,
35
+ seed=42,
36
+ )
37
+
38
+ formatted_prompt = format_prompt(history)
39
+ formatted_prompt += f"<s>[INST] {prompt} [/INST]" # Add the current prompt
40
+
41
+ stream = client.text_generation(formatted_prompt, **generate_kwargs, stream=True, details=True, return_full_text=False)
42
+
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()