Cylanoid commited on
Commit
5b0960f
·
verified ·
1 Parent(s): 112890f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -1,6 +1,16 @@
1
  import gradio as gr
2
  from transformers import LlamaTokenizer, LlamaForCausalLM
3
  import torch
 
 
 
 
 
 
 
 
 
 
4
 
5
  # Function to predict fraud based on text input
6
  def predict(input_text):
@@ -8,7 +18,7 @@ def predict(input_text):
8
  return "Please enter some text to analyze."
9
 
10
  try:
11
- # Load the fine-tuned model and tokenizer inside the function
12
  tokenizer = LlamaTokenizer.from_pretrained("./fine_tuned_llama2")
13
  model = LlamaForCausalLM.from_pretrained("./fine_tuned_llama2")
14
  model.eval()
 
1
  import gradio as gr
2
  from transformers import LlamaTokenizer, LlamaForCausalLM
3
  import torch
4
+ import os
5
+ from huggingface_hub import login
6
+
7
+ # Authenticate with Hugging Face using the token from Space secrets
8
+ hf_token = os.getenv("HF_TOKEN")
9
+ if hf_token:
10
+ login(token=hf_token)
11
+ print("Authenticated with Hugging Face token.")
12
+ else:
13
+ print("HF_TOKEN not found in environment variables. Please set it in Space secrets.")
14
 
15
  # Function to predict fraud based on text input
16
  def predict(input_text):
 
18
  return "Please enter some text to analyze."
19
 
20
  try:
21
+ # Load the fine-tuned model and tokenizer from the local directory
22
  tokenizer = LlamaTokenizer.from_pretrained("./fine_tuned_llama2")
23
  model = LlamaForCausalLM.from_pretrained("./fine_tuned_llama2")
24
  model.eval()