Spaces:
Sleeping
Sleeping
Update app.py
Browse files17 unmodified lines1819202122232425262728295 unmodified lines3536373839404142434417 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."""5 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")17 unmodified lines181920212223242526272829305 unmodified lines3637383940414243444517 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 clean_model_output(model_output):"""Ensures the model's output is valid JSON."""try:model_output = model_output.strip() # Remove extra spaces or newlinesreturn json.loads(model_output) # Convert to dictionaryexcept json.JSONDecodeError:return {} # Return empty dictionary if parsing failsdef generate_command(input_command):"""Runs the model and extracts information."""5 unmodified lines# Extract amount manuallyextracted_amount = extract_amount(input_command)# Parse the model output correctlymodel_data = clean_model_output(model_output)# Extract required variables from model outputaction = model_data.get("action", "Not found")currency = model_data.get("currency", "Not found")recipient = model_data.get("recipient", "Not found")
app.py+8-7