Canstralian commited on
Commit
b71bc0f
1 Parent(s): 6786b93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -1,23 +1,26 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
 
5
 
6
  def respond(message, history, system_message, max_tokens, temperature, top_p):
7
- messages = [{"role": "system", "content": system_message}]
8
- for val in history:
9
- if val[0]: messages.append({"role": "user", "content": val[0]})
10
- if val[1]: messages.append({"role": "assistant", "content": val[1]})
11
- messages.append({"role": "user", "content": message})
 
 
12
  response = ""
13
- for message in client.chat_completion(
14
- messages, max_tokens=max_tokens, stream=True, temperature=temperature, top_p=top_p
15
  ):
16
- token = message.choices[0].delta.content
17
  response += token
18
  yield response
19
 
20
- # Updated system message for penetration testing
21
  demo = gr.ChatInterface(
22
  respond,
23
  additional_inputs=[
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Use the specified model for inference
5
+ client = InferenceClient("canstralian/rabbit-redux")
6
 
7
  def respond(message, history, system_message, max_tokens, temperature, top_p):
8
+ # Construct a single prompt from the system message, history, and current user message
9
+ prompt = system_message + "\n"
10
+ for user_msg, assistant_msg in history:
11
+ prompt += f"User: {user_msg}\nAssistant: {assistant_msg}\n"
12
+ prompt += f"User: {message}\nAssistant:"
13
+
14
+ # Generate the response
15
  response = ""
16
+ for output in client.text_generation(
17
+ prompt, max_tokens=max_tokens, temperature=temperature, top_p=top_p, stream=True
18
  ):
19
+ token = output.token.text
20
  response += token
21
  yield response
22
 
23
+ # Set up the Gradio interface
24
  demo = gr.ChatInterface(
25
  respond,
26
  additional_inputs=[