saujasv commited on
Commit
87c604f
·
1 Parent(s): 2f63662

update for model comparison, add helpful interface labels

Browse files
Files changed (1) hide show
  1. app.py +32 -4
app.py CHANGED
@@ -1,12 +1,40 @@
 
1
  import gradio as gr
2
  from listener import Listener
3
 
4
- listener = Listener("pragmatic-programs/pragmatic-ft-listener", {"do_sample": True, "num_return_sequences": 100, "num_beams": 1, "temperature": 1, "top_p": 0.9})
 
5
 
6
  def synthesize(context):
7
- spec = [[[s[:-1], s[-1]] for s in context.split(' ')]]
8
- return listener.synthesize(spec).programs[0][0]
9
 
 
 
 
10
 
11
- iface = gr.Interface(fn=synthesize, inputs="text", outputs="text")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  iface.launch()
 
1
+ from typing import Any
2
  import gradio as gr
3
  from listener import Listener
4
 
5
+ pragmatic_listener = Listener("pragmatic-programs/pragmatic-ft-listener", {"do_sample": True, "num_return_sequences": 100, "num_beams": 1, "temperature": 1, "top_p": 0.9, "max_new_tokens": 128})
6
+ literal_listener = Listener("pragmatic-programs/listener-suffix-idx-300k", {"do_sample": True, "num_return_sequences": 100, "num_beams": 1, "temperature": 1, "top_p": 0.9, "max_new_tokens": 128})
7
 
8
  def synthesize(context):
9
+ if len(context.strip()) == 0:
10
+ return "Empty specification", "Empty specification"
11
 
12
+ spec = [[[s[:-1], s[-1]] for s in context.strip().split(' ')]]
13
+ if not all([len(s) > 0 and l in ['+', '-'] for s, l in spec[0]]):
14
+ return "Invalid specification", "Invalid specification"
15
 
16
+ pragmatic_outputs = pragmatic_listener.synthesize(spec).programs
17
+ literal_outputs = literal_listener.synthesize(spec).programs
18
+
19
+ if len(pragmatic_outputs[0]) > 0:
20
+ pragmatic_program = pragmatic_outputs[0][0]
21
+ else:
22
+ pragmatic_program = "No program found"
23
+
24
+ if len(literal_outputs[0]) > 0:
25
+ literal_program = literal_outputs[0][0]
26
+ else:
27
+ literal_program = "No program found"
28
+
29
+ return pragmatic_program, literal_program
30
+
31
+
32
+ iface = gr.Interface(
33
+ fn=synthesize,
34
+ inputs=gr.Textbox(lines=1, label="Examples", info="Enter a list of examples, separated by spaces. Each example is the string followed by a + or - indicating whether it should be accepted or rejected by the synthesized regex."),
35
+ outputs=[gr.Textbox(lines=1, label="Pragmatic model"), gr.Textbox(lines=1, label="Literal model")],
36
+ examples=["ab+ aabb+ abb+ abab-", "b0b+ aa0000bb+"],
37
+ title="Synthesizing regular expressions from examples",
38
+
39
+ )
40
  iface.launch()