RayBe commited on
Commit
5ca9d2a
·
verified ·
1 Parent(s): 47fcf38

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -24
app.py CHANGED
@@ -18,33 +18,17 @@ 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 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."""
31
  input_ids = tokenizer("extract: " + input_command, return_tensors="pt").input_ids.to(device)
32
 
33
  output_ids = model.generate(input_ids, max_length=128, num_beams=1, early_stopping=True)
34
- model_output = tokenizer.decode(output_ids[0], skip_special_tokens=True)
35
 
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")
46
-
47
- return extracted_amount, action, currency, recipient
48
 
49
  # Gradio Interface
50
  iface = gr.Interface(
@@ -52,13 +36,12 @@ iface = gr.Interface(
52
  inputs=gr.Textbox(lines=2, placeholder="Enter a command..."),
53
  outputs=[
54
  gr.Textbox(label="Extracted Amount"),
55
- gr.Textbox(label="Action"),
56
- gr.Textbox(label="Currency"),
57
- gr.Textbox(label="Recipient"),
58
  ],
59
- title="Command Extractor",
60
- description="Extracts amount separately and displays action, currency, and recipient from model output."
61
  )
62
 
63
  if __name__ == "__main__":
64
  iface.launch()
 
 
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 generate_command(input_command):
22
+ """Runs the model and extracts information, also displaying the raw model output for debugging."""
23
  input_ids = tokenizer("extract: " + input_command, return_tensors="pt").input_ids.to(device)
24
 
25
  output_ids = model.generate(input_ids, max_length=128, num_beams=1, early_stopping=True)
26
+ model_output = tokenizer.decode(output_ids[0], skip_special_tokens=True).strip()
27
 
28
  # Extract amount manually
29
  extracted_amount = extract_amount(input_command)
30
 
31
+ return extracted_amount, model_output # Show raw model output
 
 
 
 
 
 
 
 
32
 
33
  # Gradio Interface
34
  iface = gr.Interface(
 
36
  inputs=gr.Textbox(lines=2, placeholder="Enter a command..."),
37
  outputs=[
38
  gr.Textbox(label="Extracted Amount"),
39
+ gr.Textbox(label="Raw Model Output"), # Display raw output for debugging
 
 
40
  ],
41
+ title="Debugging Model Output",
42
+ description="Displays extracted amount and raw model output for debugging."
43
  )
44
 
45
  if __name__ == "__main__":
46
  iface.launch()
47
+