RayBe commited on
Commit
47fcf38
·
verified ·
1 Parent(s): 46e299f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -18,12 +18,13 @@ def extract_amount(input_text):
18
  match = re.search(r'\b\d{1,15}([.,]\d{1,15})?\b', input_text)
19
  return match.group(0) if match else "Not found" # Keep as string
20
 
21
- def parse_model_output(model_output):
22
- """Attempts to parse the model's output into a dictionary."""
23
  try:
24
- return json.loads(model_output) # Safely parse JSON
 
25
  except json.JSONDecodeError:
26
- return {} # Return an empty dictionary if parsing fails
27
 
28
  def generate_command(input_command):
29
  """Runs the model and extracts information."""
@@ -35,10 +36,10 @@ def generate_command(input_command):
35
  # Extract amount manually
36
  extracted_amount = extract_amount(input_command)
37
 
38
- # Parse the model output safely
39
- model_data = parse_model_output(model_output)
40
 
41
- # Extract required variables
42
  action = model_data.get("action", "Not found")
43
  currency = model_data.get("currency", "Not found")
44
  recipient = model_data.get("recipient", "Not found")
 
18
  match = re.search(r'\b\d{1,15}([.,]\d{1,15})?\b', input_text)
19
  return match.group(0) if match else "Not found" # Keep as string
20
 
21
+ def clean_model_output(model_output):
22
+ """Ensures the model's output is valid JSON."""
23
  try:
24
+ model_output = model_output.strip() # Remove extra spaces or newlines
25
+ return json.loads(model_output) # Convert to dictionary
26
  except json.JSONDecodeError:
27
+ return {} # Return empty dictionary if parsing fails
28
 
29
  def generate_command(input_command):
30
  """Runs the model and extracts information."""
 
36
  # Extract amount manually
37
  extracted_amount = extract_amount(input_command)
38
 
39
+ # Parse the model output correctly
40
+ model_data = clean_model_output(model_output)
41
 
42
+ # Extract required variables from model output
43
  action = model_data.get("action", "Not found")
44
  currency = model_data.get("currency", "Not found")
45
  recipient = model_data.get("recipient", "Not found")