Spaces:
Sleeping
Sleeping
Update app.py
Browse files15 unmodified lines161718192021222324252627282930313233343536373817 unmodified lines56575815 unmodified linesdef extract_amount(input_text):"""Extracts the first numeric value (with decimals) from the input text."""match = re.search(r'\b(\d+(?:\.\d+)?)\b', input_text)return match.group(1) if match else Nonedef merge_json_with_amount(model_output, amount):"""Ensures the extracted amount is inserted into the model's output JSON."""try:data = json.loads(model_output) # Try parsing the model outputexcept json.JSONDecodeError:return model_output # Return raw model output if it's not valid JSONdata["amount"] = amount# if amount:# try:# data["amount"] = float(amount) # Convert to float# except ValueError:# data["amount"] = amount # Keep as string if conversion failsreturn json.dumps(data, ensure_ascii=False)def generate_command(input_command):"""Processes the input, extracts the amount manually, and runs the model."""17 unmodified linesif __name__ == "__main__":iface.launch()15 unmodified lines161718192021222324252627282930313217 unmodified lines5051525315 unmodified linesdef extract_amount(input_text):"""Extracts the first numeric value (with decimals) from the input text."""match = re.search(r'\b(\d+(?:\.\d+)?)\b', input_text)return match.group(1) if match else None # Keep as stringdef merge_json_with_amount(model_output, amount):"""Ensures the extracted amount is inserted into the model's output JSON."""try:data = json.loads(model_output) # Try parsing the model outputif amount is not None:data["amount"] = amount # Replace model's amount with extracted amount (as string)return json.dumps(data, ensure_ascii=False)except json.JSONDecodeError:return model_output # Return raw model output if it's not valid JSONdef generate_command(input_command):"""Processes the input, extracts the amount manually, and runs the model."""17 unmodified linesif __name__ == "__main__":iface.launch()
app.py+5-10