Spaces:

File size: 948 Bytes
395be3e
08b9171
395be3e
7d70942
 
 
08b9171
 
395be3e
b6b0a01
395be3e
 
b6b0a01
 
395be3e
 
 
 
558fd9c
 
08b9171
b214c4d
08b9171
b214c4d
b6b0a01
c4fcff3
08b9171
 
 
 
 
 
 
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
import tempfile
import gradio as gr
import janus_swi as janus
import nest_asyncio

nest_asyncio.apply()

def yes_man(message, history):
    janus.consult("knowledge_base.pl")
    # tmp = tempfile.NamedTemporaryFile(suffix='.pl')

    # Open the file for writing.
    # with open(tmp.name, 'w') as f:
    with open("tmp.pl", 'w') as f:
        f.write("""% Define the person
us_citizen(john_doe)
lawfully_residing(john_doe, 'U.S.', date(1996, 1, 1))
condition(john_doe, 'Blind')""")
    # janus.consult(tmp.name)
    janus.consult("tmp.pl")
    if message.endswith("?"):
        result = str(janus.query_once("eligible_for_ssi(john_doe)"))
    else:
        result = '\n- '.join([str(r) for r in janus.query("eligible_for_ssi(john_doe)")])
    # tmp.close()
    return result

gr.ChatInterface(
    yes_man,
    title="Yes Man",
    description="Ask Yes Man any question",
    examples=["Hello", "Am I cool?", "Are tomatoes vegetables?"],
).launch()