oberbics commited on
Commit
7041fb3
Β·
verified Β·
1 Parent(s): bd336a0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -5
app.py CHANGED
@@ -3,7 +3,7 @@ from transformers import AutoTokenizer, AutoModelForCausalLM
3
  import torch
4
  import json
5
 
6
- # Initialize with error handling
7
  try:
8
  tokenizer = AutoTokenizer.from_pretrained("numind/NuExtract-1.5")
9
  model = AutoModelForCausalLM.from_pretrained(
@@ -36,14 +36,25 @@ JSON Output:"""
36
  extracted = json.loads(result[json_start:json_end])
37
 
38
  return "βœ… Success", extracted, f"<pre>{json.dumps(extracted, indent=2)}</pre>"
39
-
40
  except Exception as e:
41
  return f"❌ Error: {str(e)}", {}, f"<p style='color:red'>{str(e)}</p>"
42
 
43
- # Gradio interface
44
  with gr.Blocks() as demo:
45
- # [Keep your existing UI code here]
46
- # ...
 
 
 
 
 
 
 
 
 
 
 
 
47
 
48
  if __name__ == "__main__":
49
  demo.launch()
 
3
  import torch
4
  import json
5
 
6
+ # Initialize model with error handling
7
  try:
8
  tokenizer = AutoTokenizer.from_pretrained("numind/NuExtract-1.5")
9
  model = AutoModelForCausalLM.from_pretrained(
 
36
  extracted = json.loads(result[json_start:json_end])
37
 
38
  return "βœ… Success", extracted, f"<pre>{json.dumps(extracted, indent=2)}</pre>"
 
39
  except Exception as e:
40
  return f"❌ Error: {str(e)}", {}, f"<p style='color:red'>{str(e)}</p>"
41
 
42
+ # Gradio interface (properly indented block)
43
  with gr.Blocks() as demo:
44
+ gr.Markdown("# NuExtract-1.5 Structured Data Extractor")
45
+
46
+ with gr.Row():
47
+ with gr.Column():
48
+ template = gr.Textbox(label="Template (JSON)", value='{"fields": ["name", "email"]}')
49
+ text = gr.TextArea(label="Input Text")
50
+ btn = gr.Button("Extract")
51
+
52
+ with gr.Column():
53
+ status = gr.Textbox(label="Status")
54
+ json_out = gr.JSON(label="Output")
55
+ html_out = gr.HTML()
56
+
57
+ btn.click(extract_structure, [template, text], [status, json_out, html_out])
58
 
59
  if __name__ == "__main__":
60
  demo.launch()