Spaces:
Sleeping
Sleeping
Update app.py
Browse files8 unmodified lines9101112121314151516171819202116171842 unmodified lines616263646566727367686970718 unmodified linestokenizer = T5Tokenizer.from_pretrained(model_name)model = T5ForConditionalGeneration.from_pretrained(model_name)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")# Move model to CPU (explicitly)device = torch.device("cpu")model.to(device)
if torch.cuda.is_available(): model.half() try: model = torch.compile(model) except: pass
def extract_amount(input_text): """ Extracts the amount from the input text using a robust regex.42 unmodified lines prompt = "extract: " + input_command input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(device) # Generate output with reduced max_length and beams for faster inference output_ids = model.generate( input_ids, max_length=64, num_beams=3, # max_length=32, # Reduced for faster inference num_beams=2, # Reduced for faster inference early_stopping=True ) app.py+5-10