Spaces:
Sleeping
Sleeping
Update app.py
Browse files17 unmodified lines1819202122232425262728213022232425342627282930394041424344454647313233341 unmodified line363738555657394059604142434445464717 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 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) # Convert to dictionary except json.JSONDecodeError: return {} # Return empty dictionary if parsing fails
def generate_command(input_command): """Runs the model and extracts information.""" """Runs the model and extracts information, also displaying the raw model output for debugging.""" input_ids = tokenizer("extract: " + input_command, return_tensors="pt").input_ids.to(device) output_ids = model.generate(input_ids, max_length=128, num_beams=1, early_stopping=True) model_output = tokenizer.decode(output_ids[0], skip_special_tokens=True) model_output = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()
# Extract amount manually extracted_amount = extract_amount(input_command)
# Parse the model output correctly model_data = clean_model_output(model_output)
# 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")
return extracted_amount, action, currency, recipient return extracted_amount, model_output # Show raw model output
# Gradio Interfaceiface = gr.Interface(1 unmodified line inputs=gr.Textbox(lines=2, placeholder="Enter a command..."), outputs=[ gr.Textbox(label="Extracted Amount"), gr.Textbox(label="Action"), gr.Textbox(label="Currency"), gr.Textbox(label="Recipient"), gr.Textbox(label="Raw Model Output"), # Display raw output for debugging ], title="Command Extractor", description="Extracts amount separately and displays action, currency, and recipient from model output." title="Debugging Model Output", description="Displays extracted amount and raw model output for debugging.")
if __name__ == "__main__": iface.launch()
app.py+7-24