forked from pythaiml/automindx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIUX3.py
87 lines (70 loc) · 2.92 KB
/
UIUX3.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Import necessary modules
import gradio as gr
import fire
from enum import Enum
# Import logic and reasoning modules
from MASTERMIND import MASTERMIND
from logic import LogicTables
from reasoning import SocraticReasoning
from prediction import Predictor
from epistemic import AutoepistemicAgent
from nonmonotonic import DefaultLogic, Rule, Default # Ensure this is imported
#from socratic import SocraticQuestioner
from bdi import BDIModel
from memory import save_conversation_memory
from aglm import LlamaModel
class Model_Type(Enum):
gptq = 1
ggml = 2
full_precision = 3
def get_model_type(model_name):
if "gptq" in model_name.lower():
return Model_Type.gptq
elif "ggml" in model_name.lower():
return Model_Type.ggml
else:
return Model_Type.full_precision
def initialize_model(model_name, model_type):
models_folder = "./models/" # Ensure your models are stored here
aglm_model = LlamaModel(model_name, models_folder)
return aglm_model.model, aglm_model.tokenizer
def run_ui(model, tokenizer, is_chat_model, model_type, save_history=True):
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.Button("Clear")
conversation_memory = []
epistemic_agent = AutoepistemicAgent(initial_beliefs={'The sky is blue': True})
default_logic = DefaultLogic() # Initialize DefaultLogic
# Define some rules and defaults
default_logic.add_rule(Rule({"A"}, {"B"}))
default_logic.add_default(Default({"C"}, {"D"}))
def user(user_message, memory):
nonlocal conversation_memory
conversation_memory.append([user_message, None])
# Use DefaultLogic to handle dynamic beliefs
if default_logic.evaluate(user_message):
response = "Query validated by default logic."
else:
response = "Query not validated."
memory[-1][1] = response
return "", memory
def bot(memory):
nonlocal conversation_memory
conversation_memory = memory
instruction = memory[-1][0]
response = "Processing..."
memory[-1][1] = response
if save_history:
save_conversation_memory(conversation_memory)
return memory
msg.submit(user, inputs=[msg, chatbot], outputs=[msg, chatbot], queue=False).then(bot, inputs=[chatbot], outputs=[chatbot])
clear.click(lambda: None, inputs=None, outputs=chatbot, queue=False)
demo.launch(share=False, debug=True)
def main(model_name=None, file_name=None, save_history=True):
assert model_name, "model_name argument is missing."
model_type = get_model_type(model_name)
model, tokenizer = initialize_model(model_name, model_type)
run_ui(model, tokenizer, 'chat' in model_name.lower(), model_type, save_history=save_history)
if __name__ == '__main__':
fire.Fire(main)