-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole
More file actions
51 lines (41 loc) · 1.49 KB
/
Copy pathconsole
File metadata and controls
51 lines (41 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
# frozen_string_literal: true
begin
require "bundler/setup"
rescue LoadError
end
require "gliner"
require "irb"
model_dir = ARGV[0] || ENV["GLINER_MODEL_DIR"]
model_file = ENV["GLINER_MODEL_FILE"]
if model_dir && !model_dir.empty?
$gliner_model = model_file ? Gliner.load(model_dir, file: model_file) : Gliner.load(model_dir)
else
begin
Gliner.configure { |config| config.auto = true }
$gliner_model = Gliner.model
rescue => e
warn "No model loaded (auto-download failed: #{e.class}: #{e.message})"
warn "Set GLINER_MODEL_DIR or configure Gliner.config.model to a local model dir."
end
end
def gliner_extract(text, labels, **opts)
raise "No model loaded (set GLINER_MODEL_DIR or pass a directory arg)" unless $gliner_model
Gliner[labels][text, **opts]
end
def gliner_classify(text, tasks, **opts)
raise "No model loaded (set GLINER_MODEL_DIR or pass a directory arg)" unless $gliner_model
Gliner.classify[tasks][text, **opts]
end
def gliner_extract_json(text, structures, **opts)
raise "No model loaded (set GLINER_MODEL_DIR or pass a directory arg)" unless $gliner_model
Gliner[structures][text, **opts]
end
puts "Gliner console"
puts "- model: #{$gliner_model ? "loaded" : "not loaded"}"
puts "- helper: gliner_extract(text, labels, threshold: 0.5)"
puts "- helper: gliner_classify(text, tasks)"
puts "- helper: gliner_extract_json(text, structures)"
puts "- model variable: $gliner_model"
puts "- model dir: #{model_dir.inspect}"
IRB.start(__FILE__)