Canstralian commited on
Commit
805c0fb
·
verified ·
1 Parent(s): e0b0933

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -26
app.py CHANGED
@@ -1,12 +1,9 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- """
5
- For more information on `huggingface_hub` Inference API support, please check the docs: https://huggingface.co/docs/huggingface_hub/v0.22.2/en/guides/inference
6
- """
7
  client = InferenceClient("WhiteRabbitNeo/Llama-3.1-WhiteRabbitNeo-2-70B")
8
 
9
-
10
  def respond(
11
  message,
12
  history: list[tuple[str, str]],
@@ -27,38 +24,46 @@ def respond(
27
 
28
  response = ""
29
 
30
- for message in client.chat_completion(
31
- messages,
32
- max_tokens=max_tokens,
33
- stream=True,
34
- temperature=temperature,
35
- top_p=top_p,
36
- ):
37
- token = message['choices'][0]['delta']['content'] # check for correct key names
 
 
 
 
 
38
 
39
- response += token
40
- yield response
 
 
 
41
 
42
- """
43
- For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
44
- """
45
  demo = gr.Interface(
46
  fn=respond,
47
  inputs=[
48
- gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
49
- gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
50
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
51
- gr.Slider(
52
- minimum=0.1,
53
- maximum=1.0,
54
- value=0.95,
55
- step=0.05,
56
- label="Top-p (nucleus sampling)",
57
- ),
58
  ],
59
  outputs=[gr.Textbox()],
 
60
  )
61
 
 
 
 
 
 
 
62
 
63
  if __name__ == "__main__":
64
  demo.launch()
 
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
+ # Initialize the InferenceClient with the specified model
 
 
5
  client = InferenceClient("WhiteRabbitNeo/Llama-3.1-WhiteRabbitNeo-2-70B")
6
 
 
7
  def respond(
8
  message,
9
  history: list[tuple[str, str]],
 
24
 
25
  response = ""
26
 
27
+ try:
28
+ for message in client.chat_completion(
29
+ messages,
30
+ max_tokens=max_tokens,
31
+ stream=True,
32
+ temperature=temperature,
33
+ top_p=top_p,
34
+ ):
35
+ token = message['choices'][0]['delta']['content']
36
+ response += token
37
+ yield response
38
+ except Exception as e:
39
+ yield f"An error occurred: {str(e)}"
40
 
41
+ # Define the system message with a cybersecurity focus
42
+ system_message = (
43
+ "You are a cybersecurity expert chatbot, providing assistance on penetration testing, ransomware analysis, and code classification. "
44
+ "Your responses should be concise, accurate, and tailored to cybersecurity professionals."
45
+ )
46
 
47
+ # Create the Gradio interface with dark/light mode toggle
 
 
48
  demo = gr.Interface(
49
  fn=respond,
50
  inputs=[
51
+ gr.Textbox(value=system_message, label="System Message"),
52
+ gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max New Tokens"),
53
  gr.Slider(minimum=0.1, maximum=4.0, value=0.7, step=0.1, label="Temperature"),
54
+ gr.Slider(minimum=0.1, maximum=1.0, value=0.95, step=0.05, label="Top-p (Nucleus Sampling)"),
55
+ gr.Checkbox(label="Dark Mode", value=False), # Dark mode toggle
 
 
 
 
 
56
  ],
57
  outputs=[gr.Textbox()],
58
+ theme="dark", # Default theme
59
  )
60
 
61
+ def toggle_theme(dark_mode):
62
+ """Toggle between dark and light themes based on user input."""
63
+ return "dark" if dark_mode else "light"
64
+
65
+ # Update the theme based on the checkbox value
66
+ demo.change(fn=toggle_theme, inputs=[demo.inputs[4]], outputs=[demo])
67
 
68
  if __name__ == "__main__":
69
  demo.launch()