Elalimy commited on
Commit
864108f
·
verified ·
1 Parent(s): 1b13a92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -13
app.py CHANGED
@@ -6,27 +6,27 @@ HUGGING_FACE_USER_NAME = "elalimy"
6
  model_name = "my_awesome_peft_finetuned_helsinki_model"
7
  peft_model_id = f"{HUGGING_FACE_USER_NAME}/{model_name}"
8
 
9
- # Flask app class
10
- app = Flask(__name__, template_folder='templates') # Specify the templates folder
 
 
11
 
 
 
12
 
13
- def generate_translation(source_text, device="cpu"):
14
- # Load model configuration (assuming it's saved locally)
15
- config = PeftConfig.from_pretrained(peft_model_id)
16
- # Load the base model from its local directory (replace with actual model type)
17
- model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=False)
18
 
19
- # Load the tokenizer from its local directory (replace with actual tokenizer type)
20
- tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
21
 
22
- # Load the Peft model (assuming it's a custom class or adaptation)
23
- AI_model = PeftModel.from_pretrained(model, peft_model_id)
24
 
 
25
  # Encode the source text
26
  input_ids = tokenizer.encode(source_text, return_tensors='pt').to(device)
27
 
28
  # Move the model to the same device as input_ids
29
- model = model.to(device)
30
 
31
  # Generate the translation with adjusted decoding parameters
32
  generated_ids = model.generate(
@@ -62,4 +62,4 @@ def translate_text():
62
 
63
 
64
  if __name__ == "__main__":
65
- app.run()
 
6
  model_name = "my_awesome_peft_finetuned_helsinki_model"
7
  peft_model_id = f"{HUGGING_FACE_USER_NAME}/{model_name}"
8
 
9
+ # Load model configuration (assuming it's saved locally)
10
+ config = PeftConfig.from_pretrained(peft_model_id)
11
+ # Load the base model from its local directory (replace with actual model type)
12
+ base_model = AutoModelForSeq2SeqLM.from_pretrained(config.base_model_name_or_path, return_dict=True, load_in_8bit=False)
13
 
14
+ # Load the tokenizer from its local directory (replace with actual tokenizer type)
15
+ tokenizer = AutoTokenizer.from_pretrained(config.base_model_name_or_path)
16
 
17
+ # Load the Peft model (assuming it's a custom class or adaptation)
18
+ AI_model = PeftModel.from_pretrained(base_model, peft_model_id)
 
 
 
19
 
20
+ # Flask app class
21
+ app = Flask(__name__, template_folder='templates') # Specify the templates folder
22
 
 
 
23
 
24
+ def generate_translation(source_text, device="cpu"):
25
  # Encode the source text
26
  input_ids = tokenizer.encode(source_text, return_tensors='pt').to(device)
27
 
28
  # Move the model to the same device as input_ids
29
+ model = base_model.to(device)
30
 
31
  # Generate the translation with adjusted decoding parameters
32
  generated_ids = model.generate(
 
62
 
63
 
64
  if __name__ == "__main__":
65
+ app.run()