Thermostatic commited on
Commit
359241c
1 Parent(s): c86bf33

Fixed gated model problem

Browse files
Files changed (1) hide show
  1. app.py +3 -2
app.py CHANGED
@@ -1,18 +1,19 @@
1
  import gradio as gr
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
  import spaces
 
4
 
5
  # Set the model and tokenizer
6
  model_name = "meta-llama/Meta-Llama-3-70B-Instruct"
7
  lora_name = "Thermostatic/Llama-3-NeuralTranslate-Instructions-70b-v0.1-lora"
8
- model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
9
  tokenizer = AutoTokenizer.from_pretrained(model_name)
10
  lora_adapter = model.load_adapter(lora_name, with_head=False)
11
  model.to('cuda')
12
 
13
  @spaces.GPU
14
  def translate(input_text):
15
- input_ids = tokenizer.encode(f"Translate the following text from English to Spanish: {input_text}", return_tensors="pt")
16
  response = model.generate(input_ids, adapter_name=lora_name, max_length=1024)
17
  response_text = tokenizer.decode(response[0], skip_special_tokens=True)
18
  return f"Translated text: {response_text}"
 
1
  import gradio as gr
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
  import spaces
4
+ import os
5
 
6
  # Set the model and tokenizer
7
  model_name = "meta-llama/Meta-Llama-3-70B-Instruct"
8
  lora_name = "Thermostatic/Llama-3-NeuralTranslate-Instructions-70b-v0.1-lora"
9
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name, token=os.environ["HUGGINGFACE_TOKEN"])
10
  tokenizer = AutoTokenizer.from_pretrained(model_name)
11
  lora_adapter = model.load_adapter(lora_name, with_head=False)
12
  model.to('cuda')
13
 
14
  @spaces.GPU
15
  def translate(input_text):
16
+ input_ids = tokenizer.encode(input_text, return_tensors="pt")
17
  response = model.generate(input_ids, adapter_name=lora_name, max_length=1024)
18
  response_text = tokenizer.decode(response[0], skip_special_tokens=True)
19
  return f"Translated text: {response_text}"