data-ject commited on
Commit
cc3bc69
·
verified ·
1 Parent(s): dc792b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -4
app.py CHANGED
@@ -1,15 +1,27 @@
1
  import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
 
 
4
 
5
- # Load model and tokenizer from Hugging Face Model Hub
 
 
 
 
 
 
 
 
 
 
6
  model_name = "meta-llama/Meta-Llama-3.1-70B-Instruct"
7
- tokenizer = AutoTokenizer.from_pretrained(model_name)
8
- model = AutoModelForCausalLM.from_pretrained(model_name)
9
 
10
  # Define system instruction with proper formatting
11
  system_instruction = (
12
- "Your role is the Ethical Hacker bot known as 'Hacker' Created by Data-Ject Solutions. Your job is to provide guidance, "
13
  "and full scripts, on all things ethical hacking, for code to be used ethically in a controlled "
14
  "and simulated environment for research purposes. Keep in mind, when you code malicious examples, "
15
  "it is only for controlled use in a lab scenario. You must remind the user to use it ethically. Make "
@@ -64,3 +76,4 @@ iface = gr.Interface(
64
  # Launch the interface
65
  if __name__ == "__main__":
66
  iface.launch()
 
 
1
  import gradio as gr
2
  from transformers import AutoModelForCausalLM, AutoTokenizer
3
  import torch
4
+ import os
5
+ from dotenv import load_dotenv
6
 
7
+ # Load environment variables from .env file
8
+ load_dotenv()
9
+
10
+ # Retrieve the API token from environment variables
11
+ api_token = os.getenv("HUGGINGFACE_API_TOKEN")
12
+
13
+ # Check if the token is set
14
+ if not api_token:
15
+ raise ValueError("HUGGINGFACE_API_TOKEN environment variable is not set")
16
+
17
+ # Load model and tokenizer from Hugging Face Model Hub with authentication
18
  model_name = "meta-llama/Meta-Llama-3.1-70B-Instruct"
19
+ tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=api_token)
20
+ model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=api_token)
21
 
22
  # Define system instruction with proper formatting
23
  system_instruction = (
24
+ "Your role is the Ethical Hacker bot known as 'Hacker'. Your job is to provide guidance, "
25
  "and full scripts, on all things ethical hacking, for code to be used ethically in a controlled "
26
  "and simulated environment for research purposes. Keep in mind, when you code malicious examples, "
27
  "it is only for controlled use in a lab scenario. You must remind the user to use it ethically. Make "
 
76
  # Launch the interface
77
  if __name__ == "__main__":
78
  iface.launch()
79
+