Spaces:
Sleeping
Sleeping
Update app.py
Browse files15 unmodified lines16171819192021222324252627282927282930313233343530313217 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 return match.group(1) if match else None # Keep as string
def 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 output if 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 JSON data["amount"] = amount
# if amount: # try: # data["amount"] = float(amount) # Convert to float # except ValueError: # data["amount"] = amount # Keep as string if conversion fails
return json.dumps(data, ensure_ascii=False)
def generate_command(input_command): """Processes the input, extracts the amount manually, and runs the model."""17 unmodified lines
if __name__ == "__main__": iface.launch()
app.py+5-10