Spaces:
Sleeping
Sleeping
Update app.py
Browse files123412 unmodified lines1718192021224 unmodified lines27282930313233343536373839import reimport torchimport gradio as grfrom transformers import T5Tokenizer, T5ForConditionalGeneration12 unmodified linesmatch = re.search(r'\b\d{1,15}([.,]\d{1,15})?\b', input_text)return match.group(0) if match else "Not found" # Keep as stringdef generate_command(input_command):"""Runs the model and extracts information."""input_ids = tokenizer("extract: " + input_command, return_tensors="pt").input_ids.to(device)4 unmodified lines# Extract amount manuallyextracted_amount = extract_amount(input_command)try:model_data = eval(model_output) # Convert model output into a Python dictionaryaction = model_data.get("action", "Not found")currency = model_data.get("currency", "Not found")recipient = model_data.get("recipient", "Not found")except:action, currency, recipient = "Error", "Error", "Error"return extracted_amount, action, currency, recipient1234512 unmodified lines181920212223242526272829304 unmodified lines35363738394041424344454647import reimport jsonimport torchimport gradio as grfrom transformers import T5Tokenizer, T5ForConditionalGeneration12 unmodified linesmatch = re.search(r'\b\d{1,15}([.,]\d{1,15})?\b', input_text)return match.group(0) if match else "Not found" # Keep as stringdef parse_model_output(model_output):"""Attempts to parse the model's output into a dictionary."""try:return json.loads(model_output) # Safely parse JSONexcept json.JSONDecodeError:return {} # Return an empty dictionary if parsing failsdef generate_command(input_command):"""Runs the model and extracts information."""input_ids = tokenizer("extract: " + input_command, return_tensors="pt").input_ids.to(device)4 unmodified lines# Extract amount manuallyextracted_amount = extract_amount(input_command)# Parse the model output safelymodel_data = parse_model_output(model_output)# Extract required variablesaction = model_data.get("action", "Not found")currency = model_data.get("currency", "Not found")recipient = model_data.get("recipient", "Not found")return extracted_amount, action, currency, recipient
app.py+15-7