Spaces:
Sleeping
Sleeping
Update app.py
Browse files17 unmodified lines18192021222122232424252626272829305 unmodified lines3637383839394041414243444517 unmodified lines match = re.search(r'\b\d{1,15}([.,]\d{1,15})?\b', input_text) return match.group(0) if match else "Not found" # Keep as string
def parse_model_output(model_output): """Attempts to parse the model's output into a dictionary."""def clean_model_output(model_output): """Ensures the model's output is valid JSON.""" try: model_output = model_output.strip() # Remove extra spaces or newlines return json.loads(model_output) # Safely parse JSON return json.loads(model_output) # Convert to dictionary except json.JSONDecodeError: return {} # Return an empty dictionary if parsing fails return {} # Return empty dictionary if parsing fails
def generate_command(input_command): """Runs the model and extracts information."""5 unmodified lines # Extract amount manually extracted_amount = extract_amount(input_command)
# Parse the model output safely model_data = parse_model_output(model_output) # Parse the model output correctly model_data = clean_model_output(model_output)
# Extract required variables # Extract required variables from model output action = model_data.get("action", "Not found") currency = model_data.get("currency", "Not found") recipient = model_data.get("recipient", "Not found")app.py+8-7